Odd behaviour of *.pth files and Apache
gagsl-py2 at yahoo.com.ar
Wed Feb 27 01:38:15 CET 2008
En Tue, 26 Feb 2008 11:44:48 -0200, D'Arcy J.M. Cain <darcy at druid.net>
> On Tue, 26 Feb 2008 03:01:33 -0200
> "Gabriel Genellina" <gagsl-py2 at yahoo.com.ar> wrote:
>> En Sat, 23 Feb 2008 12:52:45 -0200, D'Arcy J.M. Cain <darcy at druid.net>
>> > I have more information now. It seems that it recurses the .pth files
>> > it finds in PYTHONPATH but not for directories found in the .pth files
>> > in site-packages. Is this expected behaviour? The documentation
>> > suggests that it should pick up both.
>> If a .pth file contains a valid directory, it is added to sys.path but
>> it's not searched for additional .pth files. From
>> "A path configuration file is a file whose name has the form
>> AND EXISTS IN ONE OF THE FOUR DIRECTORIES MENTIONED ABOVE" (emphasis by
>> (the four directories being .../lib/python2.5/site-packages,
> But that is not true. If I add a path by setting PYTHONPATH and there
> is a .pth in that directory then it is read and recursively searched
> for more .pth files. It is only when the path is added because it is
> in site-packages that it doesn't load the .pth files found.
This is not the behavior I see, at least not with 2.5.1 on Windows.
> In http://www.python.org/doc/inst/search-path.html there is
> more specific language:
> "Paths can be absolute or relative, in which case they're relative to
> the directory containing the .pth file. Any directories added to the
> search path will be scanned in turn for .pth files. See site module
> documentation for more information."
> Directories listed in .pth files in site-packages are "added to the
> search path" so they should be scanned for more .pth files.
There was a proposed patch to do that, rejected, basically because doing
so could potentially slow down the interpreter start up; see
http://bugs.python.org/issue1174614; PEP 370
http://www.python.org/dev/peps/pep-0370/ if approved, may be useful to you.
Note that you can always do the processing in sitecustomize.py, calling
site.addsitedir for all entries in sys.path until no more entries are
> This really smells like a bug in either the code or the docs. I hope
> it is in the code and will eventually be fixed.
Looks like the docs are wrong; the code in site.py, its docstring, and the
above quoted docs are slightly different.
More information about the Python-list