The Question :
574 people think this question is useful
I’m new to Python and am just trying to understand how its packages work. Presumably “eggs” are some sort of packaging mechanism, but what would be a quick overview of what role they play and may be some information on why they’re useful and how to create them?
The Question Comments :
The Answer 1
548 people think this answer is useful
Note: Egg packaging has been superseded by Wheel packaging.
Same concept as a
.jar file in Java, it is a
.zip file with some metadata files renamed
.egg, for distributing code as bundles.
Specifically: The Internal Structure of Python Eggs
A “Python egg” is a logical structure embodying the release of a
specific version of a Python project, comprising its code, resources,
and metadata. There are multiple formats that can be used to
physically encode a Python egg, and others can be developed. However,
a key principle of Python eggs is that they should be discoverable and
importable. That is, it should be possible for a Python application to
easily and efficiently find out what eggs are present on a system, and
to ensure that the desired eggs’ contents are importable.
.egg format is well-suited to distribution and the easy
uninstallation or upgrades of code, since the project is essentially
self-contained within a single directory or file, unmingled with any
other projects’ code or resources. It also makes it possible to have
multiple versions of a project simultaneously installed, such that
individual programs can select the versions they wish to use.
The Answer 2
96 people think this answer is useful
.egg file is a distribution format for Python packages. It’s just an alternative to a source code distribution or Windows
exe. But note that for pure
.egg file is completely cross-platform.
.egg file itself is essentially a
.zip file. If you change the extension to “
zip”, you can see that it will have folders inside the archive.
Also, if you have an
.egg file, you can install it as a package using
To create an
.egg file for a directory say
mymath which itself may have several python scripts, do the following step:
from setuptools import setup, find_packages
name = "mymath",
version = "0.1",
packages = find_packages()
Then, from the terminal do:
$ python setup.py bdist_egg
This will generate lot of outputs, but when it’s completed you’ll see that you have three new folders: build, dist, and mymath.egg-info. The only folder that we care about is the dist folder where you’ll find your
mymath-0.1-py3.5.egg with your default python (installation) version number(mine here: 3.5)
Source: Python library blog
The Answer 3
7 people think this answer is useful
Python eggs are a way of bundling additional information with a Python project, that allows the project’s dependencies to be checked and satisfied at runtime, as well as allowing projects to provide plugins for other projects. There are several binary formats that embody eggs, but the most common is ‘.egg’ zipfile format, because it’s a convenient one for distributing projects. All of the formats support including package-specific data, project-wide metadata, C extensions, and Python code.
The easiest way to install and use Python eggs is to use the “Easy Install” Python package manager, which will find, download, build, and install eggs for you; all you do is tell it the name (and optionally, version) of the Python project(s) you want to use.
Python eggs can be used with Python 2.3 and up, and can be built using the setuptools package (see the Python Subversion sandbox for source code, or the EasyInstall page for current installation instructions).
The primary benefits of Python Eggs are:
They enable tools like the “Easy Install” Python package manager
.egg files are a “zero installation” format for a Python package; no build or install step is required, just put them on PYTHONPATH or sys.path and use them (may require the runtime installed if C extensions or data files are used)
They can include package metadata, such as the other eggs they depend on
They allow “namespace packages” (packages that just contain other packages) to be split into separate distributions (e.g. zope., twisted., peak.* packages can be distributed as separate eggs, unlike normal packages which must always be placed under the same parent directory. This allows what are now huge monolithic packages to be distributed as separate components.)
They allow applications or libraries to specify the needed version of a library, so that you can e.g. require(“Twisted-Internet>=2.0”) before doing an import twisted.internet.
They’re a great format for distributing extensions or plugins to extensible applications and frameworks (such as Trac, which uses eggs for plugins as of 0.9b1), because the egg runtime provides simple APIs to locate eggs and find their advertised entry points (similar to Eclipse’s “extension point” concept).
There are also other benefits that may come from having a standardized format, similar to the benefits of Java’s “jar” format.
The Answer 4
2 people think this answer is useful
“Egg” is a single-file importable distribution format for Python-related projects.
“The Quick Guide to Python Eggs” notes that “Eggs are to Pythons as Jars are to Java…”
Eggs actually are richer than jars; they hold interesting metadata such as licensing details, release dependencies, etc.