1

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?

mindthief
  • 12,755
  • 14
  • 57
  • 61

4 Answers4

4

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.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • it's not clear from that link what the "lot more" is (It doesn't seem as though easy_install requires the egg format exclusively). Can you elucidate? thanks :) – mindthief Oct 28 '10 at 11:39
1

yes, and zip egg files are decompressed on the fly when you reference them making them slower than when you install it.

lamirap
  • 510
  • 1
  • 3
  • 8
1

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.

jknair
  • 4,709
  • 1
  • 17
  • 20
  • this answer, being taken out of context as it is, is a bit confusing, but reading the actual article referenced was quite useful and answered my question. – mindthief Oct 28 '10 at 11:37
0

@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? .

Community
  • 1
  • 1
ジョージ
  • 1,476
  • 1
  • 22
  • 29