[Tutor] Adding a search path PERMANENTLY?
Brian van den Broek
bvande at po-box.mcgill.ca
Sat Jul 10 20:36:13 CEST 2004
Hee-Seng Kye said unto the world upon 10/07/2004 12:37:
> Could anyone tell me how to set a Python search path PERMANENTLY? If I do:
>
> >>> import sys
> >>> sys.path.append('/users/kyeser/python/module')
>
> It's only valid while the interpreter is active and goes away when I
> restart the interpreter. Every manual I've read said something about
> setting PYTHONPATH, but I'm not sure how.
>
> I'm also curious how to set PYTHONSTARTUP. I've tried creating
> '.pythonrc.py' at my home directory, but it didn't do anything. If I
> wanted to do something like:
>
> >>> import sys
> >>> sys.ps1 = '--> '
>
> How would I make this permanent?
>
> Many thanks,
>
> Kye
>
Hi Kye,
I've just been posting about this the last few days. Here's what I (think
I) know:
1) Setting the PYTHONPATH environment variable will put the specified dirs
ahead of the standard lib dirs in sys.path. On Windows, you can set this
with autoexec.bat or, with more recent version, through the Control
Panel->System->Environment Variables. Your msg headers say your a Mac
person; I've no idea for Macs. You might try
<http://docs.python.org/mac/node7.html>, though.
2) Using .pth files will put your new dirs towards the end of sys.path.
.pth files are plain text files, one dir per line. Put them somewhere in
the unmodified sys.path. (The docs imply anywhere is sys.path, but I had
no luck with placing them in dirs added to sys.path via PYTHONPATH.)
3) PYTHONSTARTUP has effect only for interactive prompt sessions.
For more, see <http://docs.python.org/inst/search-path.html>. I may also
have had some details in my recent (last 2-3 days) Tutor posts that I've
here omitted.
HTH,
Brian vdB
More information about the Tutor
mailing list