Learning by doing.

Publish Packages to Pypi

Jul 4, 2018 • Python • Tags: Python Pypi

Step 1. Create a minimal project structure

Take my project sLMR as an example, a minimal structrue should be like below:

├── bin  # this folder is only required when you want to include an executable script
│   └── slmr
├── slmr  # this folder is always required
│   └──  # required
├──  # optional but useful
├──  # required

Step 2. Edit

Now let’s look at the It is not minimal but typical:

from setuptools import setup, find_packages

with open("", "r") as fh:
    long_description =

    name='slmr',  # required
    description="A scripting system for the Last Millennium Reanalysis (LMR) project.",
    author="Feng Zhu",
    author_email='[email protected]',
    license="MIT license",
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',

Step 3. Publish to Pypi

First, we need to register on Pypi. After that, we will use twine to generate distribution and upload to Pypi:

pip install twine  # for the first time, install this package
python sdist
twine upload dist/*  # prompt to type in username and password on Pypi

Step 4. Install the package

After the steps above, users may install the package from Pypi with

pip install slmr

As a developer, I will install the package locally with

# cd to the path of the project first, and then
pip install -e .  

This will create a soft link of the package to my PATH so that the latest modifications of the code will be immediately valid anywhere on my machine.

Tags: Python Pypi