Uploading a package on PyPI
===================================================
.. post:: 2020-10-21
:tags: python, code-snippets
:author: Adriaan Rol
:category:
These are some simple notes to remind myself how to upload a python package to PyPI.
The full description on how to upload a package to PyPI can be found `here `_.
These notes assume that you have already set up the proper folder structure, a working setup.py and all the requirements (:code:`setuptools`, :code:`wheel`, and useraccounts at PyPI and TestPyPI) for uploading to PyPI installed.
.. TEASER_END
Make sure you have the latest versions of :code:`setuptools` and :code:`wheel`
.. code-block:: sh
python3 -m pip install --user --upgrade setuptools wheel
Run this command from the same location as setup.py
.. code-block:: sh
python3 setup.py sdist bdist_wheel
This creates several files in the dist/ directory:
.. code-block::
dist/
example_pkg_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl
example_pkg_YOUR_USERNAME_HERE-0.0.1.tar.gz
If this runs without warnings you can upload to TestPyPI.
.. code-block:: sh
python3 -m twine upload --repository testpypi dist/*
After the command completes you can see the package on `https://test.pypi.org/project/example-pkg-YOUR-USERNAME-HERE `_.
If everything looks as it should you can upload to PyPI.
.. code-block:: sh
twine upload dist/*
.. note::
This procedure works well for pure python packages. Once platform dependencies creep in, it is advicable to take that into account. I recommend checking out `the python packaging tutorial (SciPy 2018) `_.