Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Import of egg packages installed with easy_install

Reply
Thread Tools

Import of egg packages installed with easy_install

 
 
Alexey Vlasov
Guest
Posts: n/a
 
      12-01-2008
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]=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.
>>> import flup


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.

--
BRGDS. Alexey Vlasov.
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      12-01-2008
Alexey Vlasov wrote:

> 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]=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.
>>>> import flup

>
> 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

 
Reply With Quote
 
 
 
 
Alexey Vlasov
Guest
Posts: n/a
 
      12-02-2008
Hi Diez.

On Mon, Dec 01, 2008 at 08:09:29PM +0100, Diez B. Roggisch wrote:

> 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.

--
BRGDS. Alexey Vlasov.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
linecache vs egg - reading line of a file in an egg R. Bernstein Python 3 12-21-2008 10:07 AM
how to do easy_install to source code, not egg? dmitrey Python 1 09-18-2008 09:08 AM
round-trip from egg to code and back to egg Catherine Python 2 10-08-2007 10:20 PM
easy_install only stable packages exhuma.twn Python 0 09-10-2007 11:58 AM



Advertisments