Reputation: 13383
It seems like just adding a package path to your PYTHONPATH gives you access to all of its modules and functions, similar to installing an egg. Is the difference just that the egg is zip compressed?
Upvotes: 2
Views: 1297
Reputation: 1566
@lamirap: not necessarily.
First, reading from the disk takes some time, especially if the module has more than one file. So if we compare reading several files from disk with no unzipping and reading one file -- that is smaller, but followed with some further unzipping overhead, the latter is not necessarily slower.
Second, in theory using eggs helps making sys.path shorter, see http://mail.python.org/pipermail/python-dev/2006-April/064544.html .
So my bottom line about performance is -- "it depends".
*See also: Disadvantage of Python eggs? .
Upvotes: 0
Reputation: 262989
Python Eggs is a package distribution system that does a lot more than simply copy files and change $PYTHONPATH
.
EDIT: A lot more
meaning e.g. runtime dependency resolution and plugin support. See http://en.wikipedia.org/wiki/EasyInstall.
Upvotes: 5
Reputation: 4764
Yes absolutely but a bit more read this http://www.ibm.com/developerworks/library/l-cppeak3.html goto section "All about eggs" copied from the above website :
However, this sort of manipulation of the PYTHONPATH (or of sys.path within a script or Python shell session) is a bit fragile. Discovery of eggs is probably best handled within some newish magic .pth files. Any .pth files found in site-packages/ or on the PYTHONPATH are parsed for additional imports to perform, in a very similar manner to the way directories in those locations that might contain packages are examined. If you handle package management with setuptools, a file called easy-install.pth is modified when packages are installed, upgraded, removed, etc. But you may call your .pth files whatever you like (as long as they have the .pth extension). For example, here is my easy-install.pth:
Listing 11. .pth files as configuration of egg locations
% cat /sw/lib/python2.4/site-packages/easy-install.pth import sys; sys.__plen = len(sys.path) setuptools-0.6b1-py2.4.egg SQLObject-0.7.0-py2.4.egg FormEncode-0.5.1-py2.4.egg Gnosis_Utils-1.2.1-py2.4.egg import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
The format is a bit peculiar: it is almost, but not quite, a Python script. Suffice it to say that you may add additional listed eggs in there; or better yet, easy_install will do it for you when it runs. You may also create as many other .pth files as you like under site-packages/, and each may simply list which eggs to make available.
Upvotes: 1
Reputation: 520
yes, and zip egg files are decompressed on the fly when you reference them making them slower than when you install it.
Upvotes: 1