Skip to content
holzkohlengrill edited this page Dec 15, 2023 · 2 revisions

Packaging for pip distribution

  1. cd into your Python project folder
  2. pip install setuptools
  3. pip install wheel (for bdist_wheel)
  4. python setup.py sdist bdist_wheel
  5. pip install twine
  6. Generate pacakages: python setup.py sdist bdist_wheel
  7. Upload
    1. pip's TEST database: twine upload --repository-url https://test.pypi.org/legacy/ dist/* (in order to upload to pip database (in this case to pip's TEST database)
    2. pip's REAL database: twine upload dist/* (in order to upload to the REAL pip database)

Additional information:

  • sdist ("source archive") creates a .tar.gz in dist/
  • bdist_wheel ("built distribution") (you need pip install wheel herefore) creates a .whl in dist/
  • bdist creates a .zip in dist/ (contains a full path structure with the relevant packages) => normally not needed
  • Test install in venv: pip install --index-url https://test.pypi.org/simple/ --no-deps packageName

See here for a lengthy documentation: https://packaging.python.org/tutorials/packaging-projects/

Auto-deploy with Travis

  1. Install the Travis CLI
  2. cd to travis install folder => e.g. /home/<usr>/.gem/ruby/2.6.0/gems/travis-1.8.9/bin/
  3. Log-in: travis login --pro
  4. Encrypt your pip password:
travis encrypt "yourPipAccountPassword" -r yourUsername/RepoName
#                                          ^^^^^^^^^^^^^^^^^^^^^--- this is where your repo lies on GitHub

=> Add this to your travis.yml:

deploy:
  provider: pypi
  user: yourUsername
  password:
    secure: yourReeeeeeeallyLongGeneratedHash
  on:
    # Deploy only on new git tags
    tags: true

Important notes:

  • User name and repo name change the key -> be sure to enter the correct repo name and user name otherwise it will fail
  • I never managed to run the Travis CLI on Windows. If you feel like I felt just use Linux (e.g. in a VM) to do this stuff.
  • Apparently you cannot state the secure hash as a environment variable in the Travis settings

Update all installed pip packages

Based on: https://stackoverflow.com/a/3452888/4773274

Authors: rbp, Dukeling

#!/bin/bash
pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 sudo pip3 install -U
Clone this wiki locally