开发者

PYTHONPATH issues with versioned package names outside of site-packages

开发者 https://www.devze.com 2023-03-19 04:21 出处:网络
In attempting to solve a package management issue here, I learned I may have issues with the way I\'m using PYTHONPATH to access packages outside of the site-packages directory.

In attempting to solve a package management issue here, I learned I may have issues with the way I'm using PYTHONPATH to access packages outside of the site-packages directory.

I receive an import error when attempting to import modules from a package (say wxPython) from its versioned directory folder name (i.e. wx-2.8-msw-unicode) when said directory is not in the python site-packages directory.

To recreate the issue: Create a directory outside of the python directory, say C:\foo. Download wxPython, and place it in that directory (giving C:\foo\wx-2.8-msw-unicode). Add more if you like. Add the directory C:\foo to your PYTHONPATH environment variable. Open a new python interactive shell and run

import sys
for i in sys.paths:
    print i

to verify that the path is there (which it is), then

import wx

I receive an 开发者_开发百科Import Error. What am I doing wrong? Is this behavior correct?


As I understand what you're saying, this is expected behaviour. C:\foo is in your Pythonpath, but it does not contain an importable wx module. For import wx to succeed, it has to find one of wx.(py/pyc/pyd/dll/so) or a directory wx containing the file __init__.py, directly in one of the directories on your Pythonpath.

The installer will normally sort out making sure this is in an importable location for you. If you want to do it yourself, you have to ensure that wx ends up in an importable location.

0

精彩评论

暂无评论...
验证码 换一张
取 消