Register accounts with pypi and testpypi (yes, you want both). From this, note that the database for TestPyPI may be periodically pruned, so it is not unusual for user accounts to be deleted.
Create the ~/.pypirc
file according to this documentation.
Example:
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository: https://upload.pypi.org/legacy/
username: jethro-q-walrustitty
password: raymond-luxury-yacht
[testpypi]
repository: https://test.pypi.org/legacy/
username: jethro-q-walrustitty
password: raymond-luxury-yacht
IMPORTANT: Because this file contains your passwords in plaintext, you will want to set the permissions to as private as possible:
chmod 600 ~/.pypirc
Omitting the password will cause the package upload to prompt for password.
Create the setup.py
file and others according to
this documentation.
The long_description
could be the contents of README.rst
for example. See this for an example.
Regarding README.rst
-- PyPi doesn't support markdown. If your project has a README.md
file using markdown (e.g. a
github-hosted project), then you can convert it into rst
format using this script.
Build a "source distribution", as documented here.
python3 setup.py sdist
This will create a .tar.gz
file in the dist
subdir. Now build a "wheel" (a built version of the package), as documented
here. For example, to build a pure-Python
wheel for a project that only supports Python 3, run the following command.
python3 setup.py bdist_wheel
This will create a .whl
file in the dist
subdir.
Now upload the distribution files you created to testpypi using twine
(why use twine instead of good ol' setup.py
?; also make sure to upgrade
twine
if necessary):
python3.6 -m twine upload -r testpypi dist/*
This will make your uploaded files available at
https://test.pypi.org/simple/<your-package-name>/
Note: Deleting packages from PyPi.
Now you can test installation of your package via pip3
.
pip3 install --index-url https://test.pypi.org/simple/ <your-package-name>
Once you're satisfied with the result, you can upload your package to the "real" index.
python3.6 -m twine upload dist/*
This will make a project page with relevant info and links available at
https://pypi.org/project/<your-package-name>/
Finally, your package can be installed as normal:
pip3 install <your-package-name>