Skip to content

Instantly share code, notes, and snippets.

@wjladams
Last active April 22, 2018 15:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wjladams/f00d6c590a4384ad2a92bf9c53f6b794 to your computer and use it in GitHub Desktop.
Creating a pip installable python module from source using pypi

Creating / Uploading pypi python module

  1. Install twine and make sure tools are up to date by running

    pip install -U pip setuptools twine
    
  2. Create an account at https://pypi.org/ and also https://test.pypi.org/, the latter for testing.

  3. Follow the instructions at Packaging and distributing project for informationa about setup.cfg and setup.py usage

  4. From the package directory run the following (assuming you want to distribute a source distribution and a wheel for the particular python you are using. A wheel distribution is essentially a packaged version that is operating system agnostic but is either python2 or python3 specific):

    python setup.py sdist bdist_wheel
    
  5. Add the example sample.pypirc file to ~/.pypirc directory and change the usernames and passwords for the testpypi and pypi servers.

  6. Upload to the testing pypi server, but running the following from your package directory:

    twine upload --repository testpypi dist/*
    
  7. Test that upload by installing:

    pip install --index-url https://test.pypi.org/simple/ your_package_name
    
  8. Actually install to pypi:

    twine upload dist/*
    
  9. You can test by running pip install your_package_name

index-servers=
pypi
testpypi
[pypi]
repository: https://upload.pypi.org/legacy/
username: PUT_NAME_HERE
password: PUT_PASSWD_HERE
[testpypi]
repository: https://test.pypi.org/legacy/
username: PUT_NAME_HERE
password: PUT_PASSWD_HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment