Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we need python packaging (e.g. egg)? [duplicate]

Tags:

python

When I need a Python library, I use pip to fetch it from PyPi and if I create a project and want to share it, I just need to have in place the setup.py file and that would make it easily installable. Therefore, I was wondering what is the use case for egg or wheel packages.

like image 298
M. Buil Avatar asked Feb 23 '17 08:02

M. Buil


1 Answers

The Python Packaging User Guide has to say the following on this topic:

Wheel and Egg are both packaging formats that aim to support the use case of needing an install artifact that doesn’t require building or compilation, which can be costly in testing and production workflows.

These formats can be used to distribute packages that contain binary extension modules. These would otherwise require compilation during installation.

If no compilation is involved a source distribution is in principle sufficient, but the user guide still recommends to create a wheel for performance reasons:

Minimally, you should create a Source Distribution:

python setup.py sdist

A “source distribution” is unbuilt (i.e, it’s not a Built Distribution), and requires a build step when installed by pip. Even if the distribution is pure python (i.e. contains no extensions), it still involves a build step to build out the installation metadata from setup.py.

[...]

You should also create a wheel for your project. A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster for the end user than installing from a source distribution.

In short, packages are a convenience thing - mostly for the user.

Wheel packages unify the process of distributing and installing projects that contain pure python, platform dependent code, or compiled extensions. The user does not need to worry if the package is written in Python or in C - it just works.

like image 169
MB-F Avatar answered Oct 06 '22 14:10

MB-F