[gobolinux-users] $pythonpath

Jonas Karlsson jonka750 at student.liu.se
Thu Nov 29 09:16:02 NZDT 2007


On Wed, 28 Nov 2007 18:51:08 +0100, <giamby at infinito.it> wrote:

> On Wed, 28 Nov 2007 15:35:43 -0200
>   "Hisham Muhammad" <hisham.hm at gmail.com> wrote:
>> On Nov 27, 2007 6:26 PM, Carlo Calica <carlo at calica.com>
>> wrote:
>>> On 11/14/07, Giambattista Bloisi <giamby at infinito.it>
>>> wrote:
>>> >
>>> > 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.
>>> >
>>>
>>> I've had time problem countless times.  I usually brute
>>> force it by
>>> adding a symlink in /Programs/Python/.../.../ but this
>>> is much better.
>>>  Could this be added to the Python recipe?
>>>
>>> add to gobolinux.pth
>>> import site;
>>> site.addsitedir('/System/Links/Libraries/python2.5/site-packages/',
>>> set())
>>>
>>> Anyone see any problems doing this?
>>
>> Mmm, I'm not sure if I got it.
>>
>> My gobolinux.pth currently looks like this:
>>
>> /System/Links/Libraries/python2.3/site-packages/
>> /System/Links/Libraries/python2.4/site-packages/
>> /System/Links/Libraries/python2.5/site-packages/
>>
>> Are you suggesting for it to look like this? (paths
>> mixed with Python code?)
>>
>> /System/Links/Libraries/python2.3/site-packages/
>> /System/Links/Libraries/python2.4/site-packages/
>> /System/Links/Libraries/python2.5/site-packages/
>> import site;
>> site.addsitedir('/System/Links/Libraries/python2.5/site-packages/',set())
>
> My suggestion was:
> /System/Links/Libraries/python2.3/site-packages/
> /System/Links/Libraries/python2.4/site-packages/
> import site;
> site.addsitedir('/System/Links/Libraries/python2.5/site-packages/',set())
>
> You do not need to list the dir put in addsitedir.
>
>> In any case, if I do this, I get:
>>
>> 'import site' failed; use -v for traceback
>>
>> everytime I launch Python. Running 'import site'
>> directly from Python
>> gives me a long stack trace, with the error:
>>
>> RuntimeError: maximum recursion depth exceeded
>>
>> I tried removing the other paths from the file, and
>> clearing the
>> $PYTHONPATH variable, but I still get the same error.
>> Does anybody
>> have any idea?
>
> Which version of python are you using ?
> I tried the conf above both with 2.5 and 2.5.1 and it
> works fine.
>
> Perhaps the recursion is caused by a .pth file inside
> /System/Links/Libraries/python2.5/site-packages/, but
> site.py should already have code to prevent this.
>
I have made some experiments. Adding the 'import...' command
to gobolinux.pth works as long as it is present only in the
Python /Programs directory. But when I symlink it into
/S/L/L/python2.5/site-packages I get infinite recursion as
well.

I've looked at the code in site.py and it has a 'if sitepath
in known_paths :' check, but only for appending the sitepath
to path. It still tries to process *.pth files in sitepath,
leading to the recursion. By indenting the following block,
handling the *.pth files this does not happen and the
addition to gobolinux.pth works. I've attached a diff with
the change. However this change changes the behaviour so
known paths can't be added as sitedirs, as it will be a
known path. Adding the 'import...' before the paths or just
not declaring the path beside the addsitedir(foo) works
around this issue. Maybe there's a better solution?

-- 
/Jonas

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python_sitedir.diff
Type: text/x-diff
Size: 784 bytes
Desc: not available
Url : http://lists.gobolinux.org/pipermail/gobolinux-users/attachments/20071128/f8274108/attachment-0001.diff 


More information about the gobolinux-users mailing list