[Tutor] Adding a search path PERMANENTLY?

Hee-Seng Kye kyeser at earthlink.net
Sat Jul 10 20:58:47 CEST 2004


Hi, Brian.  Thanks for your response.  Yes, I'm on Mac, but I mainly 
work on UNIX shell (tcsh).  Someone else (a.k.a orbitz) replied and 
directed me to the source, so the problem is solved.

I do have a question for you though.  You specifically mention that 
'setting the PYTHONPATH will put the specified dirs ahead of the 
standard lib dirs in sys.path,' and that's exactly what I experienced.  
Is new path supposed be placed where it is placed?  Does it have any 
meaning other than the fact that it will be searched before the 
standard lib paths?  You seem to be very specific about it, so I'm just 
wondering.

Thanks a lot for your response.

Best,

Kye

p.s. For those who might be asking the same question in the future, 
this is how it's done on tcsh.  Put the following line in .tcshrc (or 
.cshrc if you are on csh, I think...):

setenv PYTHONPATH "your desired path here"

It was confusing to me at first due to the absence of the '=' sign.  
The above syntax should work.


On Jul 10, 2004, at 2:36 PM, Brian van den Broek wrote:

> 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