58

The advantage of wheels over eggs is clear (see section why not egg? https://pypi.python.org/pypi/wheel).

However, it is not entirely clear to me what is the advantage of using wheels over tar.gz. I might be missing something obvious like "they are the same". As I see it both can be installed directly using pip (even in Windows), have similar size and when packaging require a similar effort. It sounds to me like the kind of questions you might get when justifying a packaging methodology.

EDIT: Just found an example where tar.gz might be better than wheels. CherryPy (https://pypi.python.org/pypi/CherryPy) provides wheels for Python 3.x only, so if you want to have a local repository to serve CherryPy for Python 2.7 and 3.x dependencies, it seems to make more sense to store the tarball. Is this correct? (just to add a couple of "case-based" justification to the discussion)

0 _
  • 10,524
  • 11
  • 77
  • 109
zom-pro
  • 1,571
  • 2
  • 16
  • 32

2 Answers2

34

This answered it for me (directly from the wheel PEP):

Python needs a package format that is easier to install than sdist. Python's sdist packages are defined by and require the distutils and setuptools build systems, running arbitrary code to build-and-install, and re-compile, code just so it can be installed into a new virtualenv. This system of conflating build-install is slow, hard to maintain, and hinders innovation in both build systems and installers.

Wheel attempts to remedy these problems by providing a simpler interface between the build system and the installer. The wheel binary package format frees installers from having to know about the build system, saves time by amortizing compile time over many installations, and removes the need to install a build system in the target environment.

https://www.python.org/dev/peps/pep-0427/#rationale

Note the tarballs we're speaking of are what are referred to as "sdists" above.

brk3
  • 1,524
  • 2
  • 19
  • 31
  • thanks, i was trying to read the setuptools documentation, and didn't understand the following sentence `the 'tests' directory will be present in the 'sdist' but not in the 'wheel'` now I know that the `tar.gz` files are the `sdist` and the `.whl` files are the "wheels" https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html – Brian W Jun 14 '23 at 15:54
12

From Python Wheels

Advantages of wheels

• Faster installation for pure python and native C extension packages.
• Avoids arbitrary code execution for installation. (Avoids setup.py)
• Installation of a C extension does not require a compiler on Windows or OS X.
• Allows better caching for testing and continuous integration.
• Creates .pyc files as part of installation to ensure they match the python interpreter used.
• More consistent installs across platforms and machines.

Make sure wheel is installed.

python3 -m pip install wheel
karel
  • 5,489
  • 46
  • 45
  • 50
  • 2
    are all those points things that tarballs cannot do? (I could easily say that you need "extra" software for wheels in a linux machine while tarball wouldn't for example) – zom-pro Jul 14 '15 at 09:03
  • 2
    I don't always know what's in a tarball, even by opening the archive, to the same degree that I know what's in a .whl file which is supposed to "just work", and that's a big advantage to me when using pip which often doesn't "just work". – karel Jul 14 '15 at 09:06
  • 2
    Could you go a bit deeper on that point? as I see it, when I look at a wheel and a tarball, both have the package zipped inside and some extra magic for packaging. Even I could say that in the tarball I can see the license right there while I can't find it in the wheel (quite an important point when doing commercial softwr). Both could hide something undesirable, that's why I don't get the "just work". (BTW, I like wheels but I need a solid justification) – zom-pro Jul 14 '15 at 09:12
  • 4
    @zom-pro: as far as I understand, the files in a wheel are just copied into place. The files in a sdist archive are processed with `setup.py` -- which normally just copies them somewhere, but it doesn't have to just copy them. So a wheel is simpler in this sense. – Martin Geisler Aug 25 '17 at 07:54