.pth files question

B

Benjamin Rutt

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,
 
M

Michael Hoffman

Benjamin said:
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.
 
P

Peter Hansen

Benjamin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top