How to use PyPi to distribute Python packages

Related: Replace/augment with pyproject.toml

This procedure is for PyPi Warehouse and requires secure, powerful twine uploader.

PyPi upload

This assumes you already have the and setup.cfg structure below.


pip >= 10
setuptools >= 38.6
twine >= 1.11
wheel >= 0.31

one-time setup

Sign up for a PyPi account.

Install Twine

python -m pip install twine

Create ~/.pypirc with the content


Note that I did NOT save my password for security.


In your Python package directory, create thee source package and upload

python sdist

twine upload dist/*

Now the package is live to the world on PyPi. Anyone can install it via

python -m pip install myprogram

Minimal, setup.cfg

Assuming your package is named myprogram, have a directory structure like


Minimal for PyPi:

from setuptools import setup; setup()

NOTE: you must always have a setuptools import when using to build distribution, EVEN IF you don’t explicitly use it. Use # noqa: F401 to quiet linters.

minimal setup.cfg for PyPi enabling Markdown README.

Pick from the list of classifiers suitable for your project.

You MUST increment the version number for each release, or PyPi will prevent upload

Error workarounds

error: Upload failed (400): Binary wheel ‘*-cp36-cp36m-linux_x86_64.whl’ has an unsupported platform tag ‘linux_x86_64’.

This error happens because currently only manylinux1 wheels are accepted by PyPi. It is not trivial to first start building manylinux1 wheels, so consider workaround: don’t upload the wheel, just the source code and your users will compile it on their machine.

python sdist
twine upload dist/*