WRITELOOP

PACKAGE PROJECT TO PYTHON'S PYPI

2019 June 4

Package your project

  • Create __init__.py inside the package (folder under the project that has the same name as the project). This file should be added to each directory on the project directory hierarchy, otherwise those directories which do not contain this file will not be packaged;
  • Fill setup.py (e.g. on my github data_sourcery project);
  • Create README.md AND LICENSE on the project root;
  • Generate distribution archives:
$ pip install --upgrade pip setuptools wheel
$ python setup.py sdist bdist_wheel

(on finishing this step, there will be packages on the dist/ folder)

Distribute your package:

Upload distribution archives:

Before moving on, make sure you have accounts on test pypi and pypi. Install twine to upload the python packages (distribution archives) you have generated earlier:

$ pip install --upgrade twine

First to test PyPI:

(take into account that testpypi may not have your project dependencies)

$ python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Then, search for it on https://test.pypi.org. Take into account that _ on package names gets replaced by -. To install from testpi into a test virtualenv:

$ pip install -i https://test.pypi.org/simple/ data-sourcery

After installing to a test virtualenv, to make sure it is working:

$ python
$ import package_name
$ package_name.__name__
'package_name'

Then to real PyPI:

$ python -m twine upload dist/*
$ pip search your-package
$ pip install your-package

TAGS