If I have a module, foo
, in Lib/site-packages
, I can just import foo
and it will work. However, when I install stuff from eggs, I get something like blah-4.0.1-py2.7-win32.egg
as a folder, with the module contents inside, yet I still only need do import foo
, not anything more complicated. How does Python keep track of eggs? It is not just dirname matching as if I drop that folder into a Python installation without going through dist-utils, it does not find the module.
To be clearer: I just installed zope. The folder name is "zope.interface-3.3.0-py2.7-win32.egg". This works:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import zope.interface
>>>
I create a "blah-4.0.1-py2.7-win32.egg" folder with an empty module "haha" in it (and __init__.py
). This does not work:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import blah.haha
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named blah.haha
>>>
This does, though:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pkg_resources import require
>>> require("blah>=1.0")
[blah 4.0.1 (c:\python27\lib\site-packages\blah-4.0.1-py2.7-win32.egg)]
>>> import haha
>>>
So how do I make it work without a require
?
import
statement's implementation without too much trouble. As they say: "Use the Source, Luke." – S.Lotteggs
andeasy_install
are not part of the Python standard library so just reading about importing modules isn't really going to answer the OP's question. – Ned Deily