[Tutor] Re: help with setting Python Path under WinMe (original) (raw)

Brian van den Broek bvande at po-box.mcgill.ca
Sat Jul 10 11🔞43 CEST 2004


Hi all,

RECENTLY I posted a question about configuring Python's search path. (I don't get my own so can't preserve the thread, but its here <http://mail.python.org/pipermail/tutor/2004-July/030402.html> What I was trying to do was use the PYTHONPATH environment variable in either the Windows Registry settings (no luck at all) or autoexec.bat (partial success) to add some directories to the end of Python's search path (the result of sys.path). The autoexec.bat way left my added directories ahead of the standard library dirs; this is what I wanted to change.

I've mostly answered my own question, so am posting for future googlers.

Well, according to section 4.1 Modifying Python's Search Path of Installing Python Modules <http://docs.python.org/inst/search-path.html> this cannot work. PYTHONPATH additions to the search path are added "to the beginning" of sys.path. However, of .pth files, documented in this same section, allows you to add directories after the standard library directory. On my system, with a bit of tinkering, it still puts them before C:\PYTHON23\lib\site-packages. But this is a big improvement. (The tinkering was needed to get my .pth file named and located such that it was read after the .pth files that various 3rd party packages had placed on my system.)

The only remaining oddity is that the docs seem to imply that the .pth files can be located anywhere on sys.path. But I tried to add a directory D:\PyPath using the autoexec.bat method for the sole purpose of holding a .pth file (this way, I wouldn't have to remember to do anything when updating to future version of Python). But my .pth file was ignored unless I put it somewhere that was on the sys.path independently of my PYTHONPATH setting. Odd, but no biggie.

Best to all,

Brian vdB



More information about the Tutor mailing list