Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upload a Universal Python Wheel for Python 2 and 3?

I have a package on PyPi and when preparing a new release I build the source distribution, build the wheel and upload, all with setuptools.

However, I've found it only uploads the wheel for the Python version used in the upload command (python and python3).

Here are the steps I'm taking:

python3 setup.py sdist
python3 setup.py bdist_wheel --universal
python3 setup.py sdist bdist_wheel upload

According to the Python Packaging User Guide:

"Universal Wheels" are wheels that are pure python (i.e. contains no compiled extensions) and support Python 2 and 3

So that seems to be the right thing for me.

After the wheel build step, I verify the wheel is built and has the filename format PACKAGE-VERSION-py2.py3-none-any.whl in dist but when I run the upload with python3 setup.py sdist bdist_wheel upload, it creates a PACKAGE-VERSION-py3-none-any.whl and uploads that.

If I run python setup.py sdist bdist_wheel upload it does the same for and uploads a Python 2-only one.

like image 323
ben_nuttall Avatar asked May 25 '15 12:05

ben_nuttall


1 Answers

The command python3 setup.py sdist bdist_wheel upload creates a new wheel distribution.

You'll need to include the same flags again on that command line:

python3 setup.py sdist bdist_wheel --universal upload

It's better to use twine to manage the uploads; it'll use an encrypted connection (setuptools uses an unencrypted connection and thus sends your username and password in the clear) and it allows you to inspect and test the distribution before uploading:

python3 setup.py sdist
python3 setup.py bdist_wheel --universal
# test the distributions
twine upload dist/*

Twine is currently also the only tool that sets the 'Py versions' metadata for PyPI correctly for universal wheels.

like image 187
Martijn Pieters Avatar answered Nov 16 '22 02:11

Martijn Pieters