[Pythonmac-SIG] How to provide additions to python path such thatall executions of a given python binary will see them?

Mario Ruggier mario at ruggier.org
Thu Jun 24 19:12:27 EDT 2004


On Jun 24, 2004, at 8:00 PM, Ronald Oussoren wrote:
> On 24-jun-04, at 16:27, Mario Ruggier wrote:
>
>> On Jun 22, 2004, at 4:25 PM, Ronald Oussoren wrote:
>>> On Friday, June 18, 2004, at 02:55AM, Kenneth McDonald  
>>> <kenneth.m.mcdonald at sbcglobal.net> wrote:
>>>
>>>> Currently, I modify my python path through inclusion of a PYTHONPATH
>>>> variable
>>>> in the .login file. However, I need to add a /local/python/packages
>>>> directory
>>>> to the path in such a manner that all executions of the system  
>>>> python
>>>> binary
>>>> see /local/python/packages. I was just wondering up the best (least
>>>> hacky)
>>>> way of doing this might be.
>>>
>>> create /Library/Python/2.3/local.pth containing the line  
>>> /local/python/packages.
>>>
>>> The exact name of the file is not important, as long as it has the  
>>> suffix '.pth'.
>>
>> What exactly should /Library/Python/2.3/local.pth contain? I.e. what  
>> is the syntax for adding a dir to pythonpath in this way?
>
> The file should contain one or more directory names, seperated by  
> newlines.

Thanks for the replies...

I have put a file mypackages.pth in Library/Python/2.3 containing the  
line:
/Volumes/Other/dev/python-packages
that corresponds well to the file system... but python does not  
see/find any modules in this location. If I run python and ask fro  
sys.path, I get:

$ pythonPython 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.path
['',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python23.zip',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/plat-darwin',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/plat-mac',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/plat-mac/lib-scriptpackages',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/lib-tk',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/lib-dynload',  
'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages']
 >>>

I am on 10,3,4. Any ideas?


>> And, are the effects of doing it this way different than the way that  
>> Jack has just posted, that is to add env. variables to  
>> ~/.MacOSX/environment.plist that are then read at login time?
>
> Jack's method is a per-user setting, mine is system-wide.
>
>>
>> In my /Library/Python/2.3 directory, the README says:
>> ====
>> This directory exists so that 3rd party packages can be installed
>> here.  Read the source for site.py for more details.
>> ====
>> But, there is no site.py ? Where should this be?
>
> $ python -c 'import site; print site.__file__[:-1]'
> /System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/site.py

Trés cool... I easily forget all these neat things about python...

mario


>> mario
>>
>>
>>> Ronald
>>>>
>>>> Thanks,
>>>> Ken McDonald
>>
>>
> --
> X|support bv            http://www.xsupport.nl/
> T:  +31 610271479       F:  +31 204416173




More information about the Pythonmac-SIG mailing list