How to upload Python packages to PyPI
Published:
Instructions for uploading a Python package to PyPI or Test PyPI, taken from the Python docs. Note that first you need to have a properly formatted pyproject.toml
or setup.py
Test PyPI
Upload to Test PyPI
Remove all files from the
dist/
folder before building the package:rm -rf dist/
- Build the package. The version number must be updated (unique) before running the following commands. All actions are performed in the command line from the root directory of the project.
python3 -m pip install --upgrade build python3 -m build python3 -m pip install --upgrade twine
- Upload the package to Test PyPI
python3 -m twine upload --repository testpypi dist/*
December 23, 2024 edit: If receiving an error during the twine upload process, run pip install pkginfo --upgrade
to update pkginfo
.
Install from Test PyPI
- Install the package from Test PyPI but installs any dependencies from the main PyPI repository:
python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple <package_name>
OR
- Install the package only from the Test PyPI repository:
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps <package_name>
PyPI
Upload to PyPI
Remove all files from the
dist/
folder before building the package:rm -rf dist/
- Build the package. The version number must be updated (unique) before running the following commands. All actions are performed in the command line from the root directory of the project.
python3 -m pip install --upgrade build python3 -m build python3 -m pip install --upgrade twine
- Upload the package to PyPI:
python3 -m twine upload dist/*
Install from PyPI
python3 -m pip install <package_name>