Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Python version to be used for building PyPi package?

Tags:

python

pypi

build

I'm building PyPi package, which is compatible with Python 3.8 and higher. That means that the minimum version of Python is 3.8, so I build the package in Python 3.8 environment.

My question is should I build package separately for Python 3.8 and 3.9? I think the thing that actually builds package is the module, build, so the version of Python doesn't matter. Isn't it?

like image 841
6991httam Avatar asked May 28 '26 11:05

6991httam


2 Answers

It depends on what you gonna publish. If you build and publish an sdist (source distribution, .tar.gz) — Python version doesn't matter. If you build and publish a source wheel — Python version doesn't matter. If you build and publish a binary wheel with compiled extension(s) written in C — Python version matters very much and you must build wheels for every major Python version separately.

like image 57
phd Avatar answered May 31 '26 06:05

phd


The version does not matter, you can technically build a package using Python 3.9 which can also work on Python 3.8. The quickest and easiest way to ensure version compatibility would be to build it on the minimum version that you intend to support, so I would suggest building once using 3.8.

If you want to test that the package will work on different Python versions, you can use tox to run your automated tests on multiple versions in an easy way (automated tests are tests that you execute through pytest or unittest).

Here is how Python does its versioning and what the versions signify. Assuming that you are building the package to have it work on version 3.8 and all subsequent 3.x versions, then if it builds and works for 3.8, it will almost certainly work for 3.9, 3.10, 3.11 etc...

Although major versions such as 2.x and 3.x (and 4.x if it ever gets released) will have enough incompatible changes between them that it is not safe to assume that they are compatible.

like image 42
Mark Avatar answered May 31 '26 06:05

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!