[Tutor] Adding a search path PERMANENTLY?

Hee-Seng Kye kyeser at earthlink.net
Sun Jul 11 00:58:07 CEST 2004


Thanks again for detailed information, Brian.  The source I was 
referring to is about how to setup environment variables in UNIX shell 
(specifically tcsh as I recall) and isn't about Python.  I left the 
link out for that reason, but I figure it would be helpful for others 
as well, so here it is ('orbitz' directed me to this site):

http://farside.ph.utexas.edu/teaching/329/lectures/node29.html

Thanks for all your help!

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

> Hee-Seng Kye said unto the world upon 10/07/2004 14:58:
>
>> 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.
>
> <SNIP>
>
> Hi Kye,
>
> my understanding is that PYTHONPATH places the new dirs in sys.path 
> before the standard lib dirs and .pth files after. (This is from the 
> docs.) This mattered to me as I had wanted after to prevent 
> accidentally over-riding standard lib, etc modules if I were to 
> inadvertently give one of my modules the same name as an existing 
> module.
>
> So, use PYTHONPATH if you want to allow the possibility of over-riding 
> standard modules (or if you are not worried about doing so by 
> accident) and use .pth files if you want to guard against naming 
> conflicts. Since .pth additions come after you can use the same names 
> as standard lib modules without breaking anything. Of course your same 
> named modules won't get imported because the standard lib ones will be 
> found first. But this seems the sort of thing you'd realize at the 
> time; the other way round, I worried that weeks or months later I 
> could be bit by a naming conflict and have a hard time figuring it out 
> at the time.
>
> I'm not sure that that answers your question. But it seems to me that 
> the two options so differ precisely so as to allow for this sort of 
> choice in behaviour. (Note though that I am merely reading the docs 
> and drawing what are, I hope, reasonable inferences; I am no 
> Python-guru ;-)
>
> You mentioned being directed to the sources. That didn't come through 
> the list. Was it site.py or somewhere else?
>
> Best to all,
>
> Brian vdB
>



More information about the Tutor mailing list