Question

I'm under the impression that Python import is supposed to automatically unzip egg files in site-packages.

My installation doesn't seem to want to auto-unzip the egg. What I tried:

(1) I used easy_install to install the suds module, which copied the egg file into site-packages. Python couldn't import it. (import suds)

(2) Then I used the --always-unzip option to easy_install. This time it gave me a directory instead of a zip file. Python still couldn't import the suds module.

(3) I renamed the directory suds. still couldn't find it.

(4) finally I copied the suds directory out of the unzipped egg directory into site-packags and Python found it (no surprise there).

for me, easy_install wasn't. What's missing here?

Rufus

Was it helpful?

Solution

By default (if you haven't specified multi-version mode), easy_installing an egg will add an entry to the easy-install.pth file in site-packages. Check there to see if there's a reference to the suds egg. You can also check the Python import path (which is the list of places Python will search for modules) like this:

import sys
print sys.path

Did you try import suds in a Python shell that was started before you easy_installed suds? That would explain the behaviour you saw. The .pth files are only read at Python startup, so the egg directory or zip file wouldn't have appeared in sys.path. Copying the suds dir from inside the egg directory worked because site-packages itself was already in sys.path. So make sure you restart Python after installing an egg.

Python will import from zip archives, but it won't unzip the archive into site-packages. That is, it won't leave the unzipped directory there after you import. (I think it reads from the zip file in-place without extracting it anywhere in the file system.) I've seen problems where some packages didn't work as zipped eggs (they tried to read data from their location in the file-system), so I'd recommend always using the --always-unzip flag as you do in (2).

You haven't given the command lines you used. Did you specify the -m option to easy_install? That will cause the egg to be installed in multi-version mode. It won't be in sys.path by default, and you'd need to use the pkg_resources.require function before trying to import it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top