How do packages and .pth files work under Windows (Py 2.0)
jonathan.gilligan at vanderbilt.edu
Tue Dec 5 08:19:39 CET 2000
I am having problems understanding how .pth files are supposed to work
under windows. The Python 2.0 documentation has several inconsistent
In one place, it says that under Windows and Mac, .pth files are only
interpreted if they are in the python root. Elsewhere the
documentation indicates that they are interpreted if they are in the
Here is the basic problem. I have packages bar, far, and gar, all of
which I want to be subpackages in the package foo, so I can write
"import foo.bar as FB". If bar is a working package, the Python
documentation suggests that II should be able to do what I want if I
put the directory bar (containing the bar package, which has a valid
__init__.py) inside a directory "site-packages\foo" and put a file
"foo.pth" in the site-packages directory with the single line "foo".
However, this does not work for me. Somehow, Python does not seem to
understand the foo.pth file, and python complains "ImportError: No
module named foo"
Here are the details:
I am trying to get the mx tools installed on my computer and have
python 2.0 built from cvs sources in D:\Sources\python\python\dist\src
and am trying to get mxTextTools installed somewhere so that I can use
the following line (from the Martel genome parsing package):
from mx import TextTools as TT
I have installed mxTextTools in
D:\Sources\Python\Python\dist\src\lib\site-packages\mx\TextTools. If I
set PYTHONPATH to
"D:\Sources\\Python\Python\dist\src\lib\site-packages\mx" then I can
"import TextTools" but if I set PYTHONPATH to
"D:\Sources\Python\Python\dist\src\lib\site-packages" then I cannot
"import mx.TextTools". I keep getting an error message:
"ImportError: No module named mx"
This occurs even if I create a "mx.pth" file in "site-packages" with
the single line "mx". I have also tried putting the "mx" directory and
the "mx.pth" file in the python root
I have the registry correctly set up:
"HKLM\Software\Python\PythonCore\2.0" has subkeys
"InstallPath" with default value "D:\Sources\Python\Python\dist\src"
"PythonPath" with default value
Can anyone help me figure out how to get packages to work in the way I
am trying to?
It would help me enormously if there were a way to get Python to print
out a list of where it looks when it tries to resolve an "import". Is
Thanks for any help that anyone can give me.
More information about the Python-list