Why doesn't my Python 2.6 auto-unzip egg files on import?
Asked Answered
G

1

2

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

Gonroff answered 2/9, 2011 at 15:58 Comment(5)
SOLVED - I never restarted IDLE after the install.Gonroff
Relevant: setuptools.readthedocs.io/en/latest/userguide/…Brokendown
Relevant: https://mcmap.net/q/635465/-why-does-easy_install-extract-some-python-eggs-and-not-othersBrokendown
Relevant: https://mcmap.net/q/666195/-how-to-make-quot-python-setup-py-install-quot-install-source-instead-of-egg-fileBrokendown
Relevant: https://mcmap.net/q/666194/-is-zip_safe-only-relevant-for-the-egg-formatBrokendown
P
2

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.

Postliminy answered 2/9, 2011 at 17:46 Comment(2)
You may be on to something with the "restart Python" idea. I'm not sure that I re-ran IDLE after the install, and I'm not sure reset inside the ide is sufficient. It would explain why it only found it when it was one level deep in site-packages and called "suds".Gonroff
SOLVED! It was the non-restart of IDLE that was the problem. I now see the suds*.egg directory in sys.path.Gonroff

© 2022 - 2024 — McMap. All rights reserved.