[gobolinux-users] $pythonpath

Giambattista Bloisi giamby at infinito.it
Wed Nov 14 21:43:41 NZDT 2007


Hi Andy,
    I had similar problems with python. It could help to read:

http://docs.python.org/inst/search-path.html

What I learned is that an easy way to add additional module paths to Python is to use pth files: they are just a list of direcories and must reside in a few directories python look for at startup (the documentation here is not very clear so trust me: I raised an issue and doc is going to be changed).
In case of gobolinux those directories are:
/Programs/Python/<version>/lib/python<major.minor>/site-packages
/Programs/Python/<version>/lib/site-python

Recipe of python 2.5 comes with a /Programs/Python/2.5.1/lib/python2.5/site-packages/gobolinux.pth path configuration file. The content of this file is:
/System/Links/Libraries/python2.3/site-packages/
/System/Links/Libraries/python2.4/site-packages/
/System/Links/Libraries/python2.5/site-packages/

So here you could add any directories you need to be added in the python search path. But you have to remember to reconstruct this file after you reinstall a fresh version of python.

My problem was yet another I wanted python to scan for pth file that were in 
/System/Links/Libraries/python2.5/site-packages/ because some python modules (PyGObject)
installed there .pth files in the hope they were actually scanned.
I found that I could scan additional path for pth files by adding a line of the following form to gobolinux.pth:
import site; site.addsitedir('/System/Links/Libraries/python2.5/site-packages/', set())

This should be ok with docs and future versions of python as site doc says that lines starting with "import " are actually executed.

I think that this could be a final solution for gobolinux distro. In this way when you have to add a dir in the search path all you have to do in the recipe is to add a .pth file in the appropriate Resources subdir. It is then symlinked to 
/System/Links/Libraries/python<major.minor>/site-packages/ and it works as we registered this path for pth file scanning.

Regards,
Giambattista 
 

Andy Feldman wrote:
> How do people manage their $PYTHONPATH environment variable? It doesn't seem 
> to include /S/L/L/python2.3/site-packages by default on my 013 system, 
> possibly due to me having messed something up in the past. I can add it to an 
> Environment file somewhere (e.g. Scripts, which uses that directory) but that 
> won't carry over when I upgrade to a newer version of Scripts.
>
> Is there a good way to make sure it has all the paths it needs to?
>
> -Andy
> _______________________________________________
> gobolinux-users mailing list
> gobolinux-users at lists.gobolinux.org
> http://lists.gobolinux.org/mailman/listinfo/gobolinux-users
>
>   


More information about the gobolinux-users mailing list