[Distutils] Obtuse warning from pkg_resources when egg and non-egg distributions clash

Arve Knudsen arve.knudsen at gmail.com
Wed Dec 15 17:49:56 CET 2010


I've just been able to properly identify why pkg_resources at times issues
an obtuse (to me at least) warning along these lines: "Module <module> was
already imported from <filename>, but <egg> is being added to sys.path". It
turns out that really that a non-egg distribution is on the module search
path before a corresponding egg distribution. If you run bin/test.py in the
attached case, you should see a demonstration of the issue.

Right now, it bit me when testing under a continuous integration slave on a
machine where the tested project is also installed as an egg. I couldn't for
the life of me understand why this warning was being issued, when I couldn't
see it on my development machine. Not before painstakingly debugging
pkg_resources, did it dawn on me that pkg_resources only complained on the
test machine since there was no egg metadata in the source tree (whereas in
my development source tree there is). Until debugging pkg_resources I
actually didn't know that a directory (i.e., with Python packages) is
considered an egg if it has a .egg-info file (with egg metadata) in it. I
just hadn't had the motivation yet to learn the egg technology that well.

Considering that pkg_resources' rationale for issuing this warning is so
difficult to derive from the message, may I suggest please that we modify
the message somewhat for added clarity? If it were more explicit, it should
be much easier to rectify the warning's cause. My suggestion is a message on
this form: "'<egg>' is being added to sys.path, but contained module
'<module>' was already imported from '<filename>'. Could this be a non-egg
distribution?". From such a warning, it should be possible to derive that
the module may have been imported from what is not considered by
pkg_resources an egg distribution (such as a clean source tree).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20101215/18ef8d4b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.zip
Type: application/zip
Size: 6458 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20101215/18ef8d4b/attachment-0001.zip>

More information about the Distutils-SIG mailing list