When a non built-in module is imported, the interpreter searches in the locations given by sys.path
. sys.path
is initialized from these locations (http://docs.python.org/library/sys.html#sys.path):
- the directory containing the input script (or the current directory)
- PYTHONPATH
- the installation-dependent default
While the first two sources are straight-forward, can anyone explain how the third one works, and what possibilities there are for influencing it?
Although I would be interested in a general solution, my specific issues are:
- I have installed the Enthought distribution 7.2 32-bit, and then Scipy-Superpack. Now enthought python tries to import numpy from
/Library/Python/2.7/
, which is where superpack installed them, instead of from the enthought site-packages. - a
wxPython
application created withpy2app
-A
does not have the samesys.path
as when starting the application withpython start_app.py
.
PYTHONPATH
, that cause an error where I have no direct access to sys.path, e.g. when building sphinx documentation. – Dig