Built distributions vs building wheels
January 12, 2024
The terms "built distributions" and "building wheels" in Python packaging refer to different aspects of preparing Python packages for distribution and installation. Here's an explanation of each term:
Built Distributions: A built distribution is a version of a Python package that has been processed and is ready for installation. This means that any steps required to prepare the package for use (like compiling code or setting up necessary files) have been completed. There are two main types of built distributions in Python:
Wheel (.whl): A Wheel is a built distribution that contains all the necessary files in a format that is easy to install without needing to compile the package. Wheel is a packaging standard for Python that aims to replace Egg. It is designed to be faster and more reliable than Egg, as it doesn’t require execution of code upon installation, reducing the risk of malicious code execution.
Source Distribution (.tar.gz or .zip): This is a package that contains source code and needs to be compiled before it can be installed. While installing from a source distribution, Python runs a setup script (setup.py) which may compile code, copy files, etc. This process can be more complex and time-consuming compared to installing a Wheel.
Building Wheels: Building a Wheel refers to the process of converting a Python package into a Wheel format. This involves taking the source code and any resources, compiling it if necessary (for packages with C extensions, for example), and then packaging it into the .whl file format. The Wheel format is convenient because it is a pre-built distribution, so the end-user does not need to compile anything. This makes the installation process faster and less prone to errors related to the build environment.
In summary, "built distributions" is a broader term that includes any format of a Python package ready for installation (like Wheels and source distributions), while "building wheels" is a specific process of creating a Wheel format distribution from a Python package. Wheels are a preferred format for Python package distribution due to their ease of use and installation.