How Is The Python Module Search Path Determined On Mac Os X?
Solution 1:
The basis of the third source is set at compile time (or configure time, more precisely), depending on the platform. It is then expanded and added to at run-time via .pth
files, etc. (which is something you can do once the Python executable is compiled to influence that third source).
This page of the Python documentation has all the information on how .pth
files work, and also more information on how sys.path
is constructed from build-time settings, etc. http://docs.python.org/library/site.html
I'm not sure why you want to influence that third source specifically though, when you can influence the whole sys.path
. Anyhow, the three ways of influencing sys.path
(without recompiling Python or patching the source code) are:
- Via the PYTHONPATH environment variable.
- By creating
.pth
files and dropping them where Python scans for packages. (See the link earlier for details.) Programmatically, by importing
sys
and then appending or prepending tosys.path
import sys sys.path.insert(0, '/this/path/will/be/considered/first')
Hopefully one of these three ways should help you do what you want.
Solution 2:
On a Mac OS X 10.7.5 system, I also had the problem that Enthought python was looking for modules in /Library/Python/2.7/. Apparently, this was caused by the file easy-install.pth located in /Library/Python/2.7/site-packages. After changing the extension of this file Enthought python imported the Enthought modules (from /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages).
Post a Comment for "How Is The Python Module Search Path Determined On Mac Os X?"