This whole discussion so far has been back-to-front. We’ve started with some assumptions about pip
, and NumPy, and used those to play around a little. Let’s take a step back.
The purpose of a distribution¶
What is the purpose of a distribution? Well, it exists to solve the following problems:
- Bundle a Python Import package into a sharable container
- Store metadata like the version of the package, and author contact details!
- List other distribution packages that are used by this package.
For example, you might write some analysis code that needs to be able to import NumPy in order to perform some array calculations. You might need an older version of NumPy that still supports a particular feature. How do you signal to your users that this is the case? This is the purpose of a distribution: to encode additional information alongside your code.
Two kinds of distributions¶
There are two kinds of distribution that Python packaging knows about:
- Binary distribution
- An archive containing exactly the files that need to be copied when installing the package.
- Source distribution
- A raw archive of the source code. From a source distribution, it is possible to build a Binary distribution.
Er... this is a bit technical. The most important bit is very easy to miss:
Source distributions are known as “sdists”. Binary distributions are known as “wheels”, hence the .whl
extension. If you want to know why the name “wheel”, it’s Monty Python. It’s always Monty Python with Python! We’ll use the words “wheel” and “binary distribution” interchangeably from now on.
Some people in the room might be wondering — “how can you author a single package that can run on anyone’s computer?”. After all, if installing a wheel is as simple as copying files, then there’s no way to customise the installation. Good question. Recall the tags that we saw in a previous section:
numpy-2.3.1-cp312-cp312-manylinux_2_28_x86_64.whl
Here, these -XXX
parts have special meaning:
-cp311
- “CPython 3.11”, the version of Python this wheel was built for.
-manylinux_2_28_x86_64
- The kind of operating system that the wheel is designed to run on.
You might be seeing where this is going; the wheel installation is not customisable, but we can build a unique wheel for the particular Python version and operating system we are interested in. This is advanced detail, that we won’t cover more on for now.