Import of egg packages installed with easy_install

Discussion in 'Python' started by Alexey Vlasov, Dec 1, 2008.

  1. 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.
    >>> 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.
    Alexey Vlasov, Dec 1, 2008
    #1
    1. Advertising

  2. 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: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
    Diez B. Roggisch, Dec 1, 2008
    #2
    1. Advertising

  3. 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.
    Alexey Vlasov, Dec 2, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles Sanders
    Replies:
    1
    Views:
    374
    Ben Finney
    Mar 21, 2007
  2. Catherine
    Replies:
    2
    Views:
    317
    John Nagle
    Oct 8, 2007
  3. Replies:
    3
    Views:
    449
    Jason
    Apr 28, 2008
  4. dmitrey
    Replies:
    1
    Views:
    287
    Diez B. Roggisch
    Sep 18, 2008
  5. R. Bernstein
    Replies:
    3
    Views:
    364
    R. Bernstein
    Dec 21, 2008
Loading...

Share This Page