15

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.

M. Buil
  • 529
  • 1
  • 4
  • 22
  • 2
    I know what it is. I don't understand the need for it because the compilation concept does not apply to python as it applies to, for example, C or java. – M. Buil Feb 23 '17 at 09:35

2 Answers2

9

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.

Community
  • 1
  • 1
MB-F
  • 22,770
  • 4
  • 61
  • 116
  • 1
    thanks but normally all the projects I work with just have config files and python scripts so there is no need for compilation. Therefore I assume that packaging is not something which is normally used or needed (at least in my case) – M. Buil Feb 23 '17 at 09:32
  • Thanks! My question is answered :) – M. Buil Feb 23 '17 at 10:52
8

Egg packages are an older standard, you should ignore them nowadays. Use pip install . instead of ./setup.py install to prevent creating them. (addendum: They are also .zips in disguise, from which Python reads package data — not exactly the most performant solution)

Wheel packages, on the other hand, are the new standard. They allow for creation of portable binary packages for Windows, macOS, and Linux (yes, Linux!). Nowadays, you can just do pip install PyQt5 (as an example) and it will just work, no C++ compiler and Qt libraries required on the system. Everything is pre-compiled and included in the wheel. Non-binary packages also benefit, because it’s safer not to run setup.py (all the metadata is in the wheel). (addendum: those are also .zips, but they are unpacked when installed)

Chris Warrick
  • 1,571
  • 1
  • 16
  • 27
  • Thanks. However, wheel packages do not bring any benefit if my project contains only python scripts and config files, right? – M. Buil Feb 23 '17 at 09:34
  • 1
    @M.Buil http://pythonwheels.com/ — *Avoids arbitrary code execution for installation. (Avoids setup.py). Creates .pyc files as part of installation to ensure they match the python interpreter used. More consistent installs across platforms and machines.* – Chris Warrick Feb 23 '17 at 12:00