Python egg is an older version of the Python wheel package containing the metadata and installation information about a particular python package. It is usually present as a
.zip file, composed of logical information, resources and source code of a python module or library.
A python egg can be physically encoded but it has been superseded by the python wheel package. Nowadays, python eggs are replaced by python wheel packages which perform the same functions.
Difference between wheel and egg files
Before pip install and wheel packages, .egg files were used for installing and uninstalling python packages from local systems.
As of 2023, Python egg files have completely been replaced by wheel files which have a more defined and structured method of storing metadata and installation resources of python files.
Wheel is a distribution format used for making installations for python. On the other hand, the egg format was both a runtime as well as a distribution package. These files were importable which is unlike python wheel packages.
Wheel packages have an official binary package called the official PyPA specifications, containing a list of all active interrelated specifications. This specification package was preceded by the .PEP 427 official support page.
Python Egg File Formats
Python currently supports three different versions of the egg file format.
.egg format:This is the file that contains the metadata and source code of a package.
.egg-info format:This file contains the metadata of the project located adjacent to the .egg file.
.egg-link format: This file is occasionally encountered which is only used to make a reference to a
.eggfile. This is not an actual file, it just points to the .egg file. They came into existence to make cross platform alternative to links.
Even though .egg format is not used anymore in the newer versions of python, instead , wheel files are used for setup. But regardless we can still create and use egg files in older versions of python by using the setuptools and build modules.
Prerequisites for Creating Egg Files
In order to use the modules, namely, setuptools and build you will need to install them in your system.
The setuptools package helps in easy installation/uninstallation of python tools. It also makes setting up of modules easier and faster. We can also upgrade existing packages with this.
The build module helps in configuring local command line code and in smooth running of commands. You can easily switch between different projects using this module. These tools are only accessible through the project directory.
We will also use the
find_packages() function from setuptools.
Now, we have to run the following code to install these two packages in our system.
pip install setuptools pip install 1build
Also read: Conda vs Pip: Choosing your Python package manager.
Creating a Python .egg file
Running the code below will create an .egg file for us:
# importing the required modules from setuptools import setup, find_packages #creating a setup file setup( name = "ourfile", version = "0.1", packages = find_packages() )
Now, we have to run the following in the terminal:
python setup.py bdist_egg
After running the above code in the terminal, you should ideally see that there are three new folders that will be created namely,
Note: For many systems, this might give an error because the most widely used distribution package is wheels for the newer versions of python. It is recommended to use wheel files for newer installations and avoid .egg files since they are obsolete as of now.
Also read: Could Not build Wheels for Numpy(Solved).
.egg format is suited for easy package installation and also used for upgrading existing modules. It is basically a
.zip file that is an older version of the python wheel file . Nowadays, python eggs are obsolete, so it is advisable to create python wheel files so they can be easily used for the newer versions of python. Creating egg files can also raise errors due to version mismatch. To know more about python eggs, visit the official python archive.