.pth files sorted out. I first ran into this with easy_install (here). The Python library docs are here.A path configuration file is a file whose name has the form package.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path. Non-existing items are never added to sys.path, but no check is made that the item refers to a directory (rather than a file). No item is added to sys.path more than once. Blank lines and lines beginning with # are skipped. Lines starting with import (followed by space or tab) are executed.
The four directories are:
sys.prefix + lib/site-packages
sys.prefix + lib/site-python
sys.exec_prefix + lib/site-packages
sys.exec_prefix + lib/site-pythonSo, not all directories on the path are searched for
.pth files. I made a nested directory:and put a
.pth file in site-packages:To test it:
Of course, I could have just added a path to
PYTHONPATH in ~/.bash_profile:You need to restart Terminal to see the effect of changes to
PYTHONPATH.It's worth emphasizing (as pointed out in the quote) that .pth files can contain code. Here is
easy_install.pth:It seems roundabout, but
easy_install.pth is first adding these paths to sys.path, and then moving them to the position in the path specified by sys.__egginsert.