Python Wheels
This week, I tried to install a Python package called mlc-llm for a side project, but its pip install pipeline was broken. The webpage that hosts its wheels was down, so pip kept hitting an endpoint that returned a 404. To work around it, I went to mlc-llmβs GitHub repo, found the release artifacts, and manually downloaded and installed the wheels.
I donβt remember the last time pip install failed in a way that forced me to do that, and honestly, before this, I didnβt really know what wheels were. In this article, I will explain what they are, and how they make installing Python packages fast and reliable.
- Credit: I learned about Python wheels from this post, and Iβll be using the same examples.
PyPI (Python Package Index) is the public registry where Python packages are published. pip is the installer that downloads those packages (usually from PyPI) and installs them into your current environment.
But what exactly is getting downloaded? Depending on the package, pip might download a source distribution (sdist) or a wheel (whl). Letβs unpack what those are, and how theyβre different.
Letβs start with source distributions. An sdist contains the packageβs source code (plus the build/config files needed to install it). If the project includes any native code, that source has to be built on your machine to match your OS and architecture before it can be installed.
Letβs look at an example. uWSGI v2.0 is a package where pip installs from an sdist.
$ python -m pip install 'uwsgi==2.0.*'Collecting uwsgi==2.0.* Downloading uwsgi-2.0.18.tar.gz (801 kB) |ββββββββββββββββββββββββββββββββ| 801 kB 1.1 MB/sBuilding wheels for collected packages: uwsgi Building wheel for uwsgi (setup.py) ... done Created wheel for uwsgi ... uWSGI-2.0.18-cp38-cp38-macosx_10_15_x86_64.whl Stored in directory: /private/var/folders/jc/8_hqsz0x1tdbp05 ...Successfully built uwsgiInstalling collected packages: uwsgiSuccessfully installed uwsgi-2.0.18In the pip install logs, we see that a .tar.gz file is first installed (thatβs the sdist). Then pip builds a macOS wheel on my machine, and installs that result. So when pip installs from an sdist, the flow is basically: download source β build locally β install.
But letβs take a step back: what does it actually mean to βbuild source into a macOS wheelβ?
To see why wheels matter, consider a package that isnβt pure Python, one that includes extension modules. An extension module is something you import from Python, but its implementation is compiled native code (often C/C++/Rust) rather than a .py. In other words, itβs a Python wrapper around fast, low-level code.
A .whl file is really just a structured archive (basically a .zip). For a pure-Python project, it contains the .py files plus some metadata. But if the package includes extension modules, the wheel also bundles the compiled extension binaries. Thatβs why wheels are platform-specific: compiled code has to match a particular OS and CPU architecture. So now we know whatβs happening when pip installs an sdist and builds a macOS wheel locally.
This download source β build locally β install pipeline has a few downsides. Even when pip handles the build automatically, it can be slow (compiling native code takes time) and fragile (it can fail if your machine isnβt set up as a build environment). Many projects rely on external tooling (compilers, build systems like CMake/Meson/Ninja, and system libraries/headers) that might not be installed or configured correctly. When that happens, pip install turns into a build debugging session instead of a one-line install.
Today, many packages publish pre-built wheels to PyPI, so pip install can download the wheel that matches your platform instead of building from source. Wheel filenames follow a standard naming scheme that encodes compatibility (Python version/ABI and the target OS/architecture), so pip can choose the right one automatically.
{dist}-{version}(-{build})?-{python}-{abi}-{platform}.whlThere are also a few special tags worth calling out. A py3-none-any wheel is a pure-Python wheel: it has no compiled extensions (none), and it can run on any OS and architecture (any). That makes it the most portable kind of wheel.
On Linux, youβll often see manylinux wheels. These are built against a conservative baseline so the same wheel can run across a wide range of Linux distributions, including older ones.
So if we look at the pip install logs here, thereβs no βbuildβ stage. pip just downloads a matching wheel and installs it.
$ python -m pip install 'chardet==3.*'Collecting chardet Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB) |ββββββββββββββββββββββββββββββββ| 133 kB 1.5 MB/sInstalling collected packages: chardetSuccessfully installed chardet-3.0.4In this post, I broke down the difference between source distributions and wheels, and why wheels usually make pip install fast and reliable. Hopefully I wonβt encounter another situation like I did with mlc-llm, but understanding how wheels work makes these installation issues a lot less mysterious.