Import of egg packages installed with easy_install

A

Alexey Vlasov

Hi.

There's an already installed with easy_install packet, let's say flup,
to the home catalog:
$ ls -la ~/python/lib/python2.5/site-packages/
total 176
drwxr-xr-x 3 4096 Nov 29 18:57 .
drwxr-xr-x 3 4096 Nov 29 18:51 ..
-rw-r--r-- 1 208 Nov 29 18:57 easy-install.pth
-rw-r--r-- 1 134573 Nov 29 18:51 flup-1.0.1-py2.5.egg
-rw-r--r-- 1 2362 Nov 29 18:51 site.py
-rw-r--r-- 1 1853 Nov 29 18:51 site.pyc


$ cat ~/python/lib/python2.5/site-packages/easy-install.pth
import sys; sys.__plen = len(sys.path)
../flup-1.0.1-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =
p+len(new)

$ echo $PYTHONPATH
/usr/lib64/portage/pym:/home/username/python/lib64/python2.5/site-packages

$ python
Python 2.5.2 (r252:60911, Nov 13 2008, 15:01:36)
[GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
No errors.

Then I create a simple CGI script:
========
#!/usr/bin/python

print "Content-type: text/plain";
print

import sys
sys.path.insert (0,
'/home/username/python/lib64/python2.5/site-packages')
print sys.path
import flup
========

Browser says:
['/home/username/python/lib64/python2.5/site-packages',
'/home/username/http', '/usr/lib64/python25.zip',
'/usr/lib64/python2.5', '/usr/lib64/python2.5/plat-linux2',
'/usr/lib64/python2.5/lib-tk', '/usr/lib64/python2.5/lib-dynload',
'/usr/lib64/python2.5/site-packages']

in error log:
[Sat Nov 29 19:41:15 2008] [error] Traceback (most recent call last):
[Sat Nov 29 19:41:15 2008] [error] File "path.cgi", line 9, in <module>
[Sat Nov 29 19:41:15 2008] [error] import flup
[Sat Nov 29 19:41:15 2008] [error] ImportError: No module named flup


If you start it with console, you get the same, but there appears also
another path:
/home/username/python/lib64/python2.5/site-packages/flup-1.0.1-py2.5.egg

As I understand it is the problem actually, but I can't get why sys.path
doesn't contain this path when I request with HTTP.
 
D

Diez B. Roggisch

Alexey said:
Hi.

There's an already installed with easy_install packet, let's say flup,
to the home catalog:
$ ls -la ~/python/lib/python2.5/site-packages/
total 176
drwxr-xr-x 3 4096 Nov 29 18:57 .
drwxr-xr-x 3 4096 Nov 29 18:51 ..
-rw-r--r-- 1 208 Nov 29 18:57 easy-install.pth
-rw-r--r-- 1 134573 Nov 29 18:51 flup-1.0.1-py2.5.egg
-rw-r--r-- 1 2362 Nov 29 18:51 site.py
-rw-r--r-- 1 1853 Nov 29 18:51 site.pyc


$ cat ~/python/lib/python2.5/site-packages/easy-install.pth
import sys; sys.__plen = len(sys.path)
./flup-1.0.1-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =
p+len(new)

$ echo $PYTHONPATH
/usr/lib64/portage/pym:/home/username/python/lib64/python2.5/site-packages

$ python
Python 2.5.2 (r252:60911, Nov 13 2008, 15:01:36)
[GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
No errors.

Then I create a simple CGI script:
========
#!/usr/bin/python

print "Content-type: text/plain";
print

import sys
sys.path.insert (0,
'/home/username/python/lib64/python2.5/site-packages')
print sys.path
import flup
========

Browser says:
['/home/username/python/lib64/python2.5/site-packages',
'/home/username/http', '/usr/lib64/python25.zip',
'/usr/lib64/python2.5', '/usr/lib64/python2.5/plat-linux2',
'/usr/lib64/python2.5/lib-tk', '/usr/lib64/python2.5/lib-dynload',
'/usr/lib64/python2.5/site-packages']

in error log:
[Sat Nov 29 19:41:15 2008] [error] Traceback (most recent call last):
[Sat Nov 29 19:41:15 2008] [error] File "path.cgi", line 9, in <module>
[Sat Nov 29 19:41:15 2008] [error] import flup
[Sat Nov 29 19:41:15 2008] [error] ImportError: No module named flup


If you start it with console, you get the same, but there appears also
another path:
/home/username/python/lib64/python2.5/site-packages/flup-1.0.1-py2.5.egg

As I understand it is the problem actually, but I can't get why sys.path
doesn't contain this path when I request with HTTP.

It's not sufficient to add simply your local site-packages, you must install
it using the module site's addsitedir-function, like this:

import site
site.addsitedir("/home/username/python/lib/python2.5/site-packages")

The reason is that otherwise the *.pth-files in the site-packages aren't
picked up.

Diez
 
A

Alexey Vlasov

Hi Diez.

It's not sufficient to add simply your local site-packages, you must install
it using the module site's addsitedir-function, like this:

import site
site.addsitedir("/home/username/python/lib/python2.5/site-packages")

Thanks for help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top