By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

.pth files question

P: n/a
Am I correct in understanding that:

1) foo.pth will be used if it is in the directory
/usr/lib/python-2.4/site-packages

2) foo.pth will not be read from if it is only placed somewhere in the
PYTHONPATH environment, such as foo.pth exists as the file
/tmp/bar/foo.pth, where PYTHONPATH contains "/tmp/bar"?

Thanks,
--
Benjamin Rutt
Sep 2 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Benjamin Rutt wrote:
Am I correct in understanding that:

1) foo.pth will be used if it is in the directory
/usr/lib/python-2.4/site-packages

2) foo.pth will not be read from if it is only placed somewhere in the
PYTHONPATH environment, such as foo.pth exists as the file
/tmp/bar/foo.pth, where PYTHONPATH contains "/tmp/bar"?


Yes. All this is done by the site module.
--
Michael Hoffman
Sep 2 '05 #2

P: n/a
Benjamin Rutt wrote:
Am I correct in understanding that:

1) foo.pth will be used if it is in the directory
/usr/lib/python-2.4/site-packages

2) foo.pth will not be read from if it is only placed somewhere in the
PYTHONPATH environment, such as foo.pth exists as the file
/tmp/bar/foo.pth, where PYTHONPATH contains "/tmp/bar"?


Both by inspection of the source and by experimentation, it appears you
are correct. As the docs say, only the "site-specific paths" (i.e.
sys.prefix and sys.exec_prefix, and lib/python<version>/site-packages
and lib/site-python) are actually scanned for .pth files, plus any paths
added as a result of parsing .pth files that are found.

If you want to modify or extend this behaviour, you should take
advantage of sitecustomize.py by adding your own behaviour, perhaps
scanning os.environ['PYTHONPATH'] to look for .pth files.

-Peter
Sep 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.