2016-pycon-tutorial
2016-pycon-tutorial copied to clipboard
Posting your project to PyPI
Whenever you pip install a package, it's being pulled from PyPI, the central Python package database. If you want your projects to be pip installable, you'll need to put them there. This example will use the Test PyPI server, but can be trivially modified to use the main PyPI repo.
-
Register for an account on Test PyPI: https://testpypi.python.org/pypi
-
save credentials and configurations to
~/.pypirc(if you're on Windows,%userprofile%/.pypirc)[distutils] index-servers= pypi pypitest [pypitest] repository = https://testpypi.python.org/pypi username = <your user name goes here> password = <your password goes here> [pypi] repository = https://pypi.python.org/pypi username = <your user name goes here> password = <your password goes here> -
Create source package:
python setup.py sdist- This bundles up all your files and preps them for PyPI.
- This creates a new directory called
dist/in your project directory.
-
The default way of interacting with PyPI using setuptools is insecure. Instead, we'll use twine:
pip install twine -
Now use
twineto register your package with PyPI. Run this from your project directory:twine register -r pypitest dist/<package> -c ~/.pypirc<package>is the.tar.gzfile in the dist directory which was created earlier. It should correspond to thenamefield from yoursetup.py, not the project name on github.- (if you're on Windows,
twine register -r pypitest dist/<package> -c %userprofile%/.pypirc)
-
And upload it!
twine upload dist/<package>
Further reading is provided here: https://packaging.python.org/en/latest/