When installing with pip (or from PyPI in general), wheels are much faster than source distributions, even for pure-Python projects.
Packages with native code are a clearer win, because the wheel file will contain pre-compiled binaries for the platform you’re installing on. This means that you don’t need to have a compiler and non-Python build dependencies installed, and you don’t need to wait for the compiler to do its thing.
The quick answer
Installing from a wheel is analogous to unpacking a zip file. When installing from a source distribution, pip will actually build a wheel from the source distribution and then install using that wheel. It’s the same operation at the end of the day, but there’s a bunch of extra “work” involved in building a wheel from a source distribution (which contributes to making things slower).
The picture answer
The wordy answer
When installing from a wheel, pip will fetch the wheel file, and then unpack it. That’s it. There’s nothing else to do.
When installing from a source distribution, pip will fetch the source distribution, unpack it to a temporary directory, (potentially) create a build environment and install build-dependencies in that environment, make a subprocess call (or multiple) to the build-backend to get it to generate a wheel file. The build environment and unpacked sources are then deleted. We now have a wheel file which will then be handled like any other wheel file.
Further reading
- How pip builds packages from source
- Specification of the wheel format
- Installer’s installation logic code, if you’re inclined that way
- pypackaging-native: “a collection of content about key Python packaging topics and issues for projects using native code” (which is what made me write this post)