[Python-Dev] .pth files in current or script directory

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu May 13 19:51:09 EDT 2004


A discussion (last week?) on c.l.py prompted a thought about .pth files.
Feel free to shoot it down ;)

The discussion in question concerned someone using a version control
system, and needing to change PYTHONPATH depending on which branch they
were in.

My immediately two thoughts were:

1. Use a build system (e.g. make) to set PYTHONPATH appropriately. This
is they type of thing we do.

2. Use a .pth file in the directory the code is run from (or possibly,
the same directory as the script).

Before posting the second, I thought I'd better try it out - fortunately
for me :) Putting a .pth in the current or script directory did nothing.

I'm wondering if anyone sees utility in being able to put a .pth file in
those locations and have them used in the same way as if they were in
the python executable directory.

For example, if you have a package 'p', with a 'test' subpackage
(containing scripts), it would be very simple to stick a 'test.pth' file
into the 'p.test' package, with the sole contents of 'test.pth' being
'..'. This would add the (absolute path of the) parent directory to the
root paths for module import.

I feel there's some kind of link here with PEP 328, but I'm not quite
sure where it fits.

Tim Delaney 



More information about the Python-Dev mailing list