How do packages and .pth files work under Windows (Py 2.0)
mfletch at tpresence.com
Tue Dec 5 10:17:05 CET 2000
Okay, here is the basic deal. You want to make your directory look something
You _don't_ want mx to be in your Python path if you want to do
from mx import TextTools
To see what your current Python path is...
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import sys
['', 'd:\\bin\\lang\\py2\\pythonwin', 'd:\\bin\\lang\\py2\\win32',
g\\py2\\win32\\lib', 'd:\\bin\\lang\\py2', 'd:\\bin\\lang\\py2\\dlls',
\lib-tk', 'd:\\bin\\lang\\py2\\numeric', 'd:\\bin\\lang\\py2\\pil']
As you can see, I don't have lib/site-packages in my Python path (or even on
my disk, for that matter). For what most people seem to do on Win32 (to the
best of my knowledge), is to use the base Python directory for all
"well-behaved package-structured" modules. That is, my directory structure
looks something like (for my 1.5.2 version of TextTools):
And without any .pth files, that works fine. Similarly, had I put the same
(lib being on the Python path), it should also work, again, without the use
of .pth files. That's actually the nice thing about properly packaged
systems, you don't need to muck around with reconfiguring your Python path,
you just drop them into an existing directory.
Hope this helps,
From: Jonathan Gilligan [mailto:jonathan.gilligan at vanderbilt.edu]
Sent: Tuesday, December 05, 2000 2:20 AM
To: python-list at python.org
Subject: How do packages and .pth files work under Windows (Py 2.0)
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