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
By default (if you haven’t specified multi-version mode), easy_installing an egg will add an entry to the
easy-install.pthfile 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:Did you try
import sudsin a Python shell that was started before you easy_installed suds?That would explain the behaviour you saw. The
.pthfiles are only read at Python startup, so the egg directory or zip file wouldn’t have appeared insys.path. Copying thesudsdir from inside the egg directory worked becausesite-packagesitself was already insys.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.requirefunction before trying to import it.