Background
Recent interest has written several Python libraries, also published on the PyPI, although no one to download, but they are used on other machines will be very convenient. Here I will show you how to publish your own Python library on PyPI.
Prepare to register your account
It is obvious to register an account with PyPI.
Install the necessary library Setuptools
The environment in which PIP is installed in principle has setuptools, but does not affect you to try to upgrade it.
pip install --upgrade setuptools
Twine
This is a tool that simplifies the process of publishing libraries to PyPI, which is described later in the use.
pip install --upgrade setuptools
Clone Warehouse (recommended)
The famous requests library of the author of the Great God Kennethreitz for everyone to prepare a warehouse as a setup.py good template, of course you can also hand-written setup.py.
clone https://github.com/kennethreitz/setup.py
Coded edit setup.py
We recommend that you directly edit the setup.py in the previous warehouse, only need to modify some of the necessary configuration. This is the configuration of the library Condition_chain I wrote recently.
...# Package meta-data.NAME = ‘condition_chain‘DESCRIPTION = ‘Process a series of conditional judgement with a chained call.‘URL = ‘https://github.com/duyixian1234/condition_chain‘EMAIL = ‘[email protected]‘AUTHOR = ‘Yixian Du‘# What packages are required for this module to be executed?REQUIRED = [ # ‘requests‘, ‘maya‘, ‘records‘,]...
Writing Core Code
Next we can write our own code, note that the Source code folder (the My_package folder in the warehouse) name and setup.py in the configuration of the package name (name) to be consistent.
Also before re-uploading, we need to change the version number in the __version__.py to avoid overwriting the previous upload (believe that someone will need the previous version of the library).
The final code structure
│ LICENSE│ MANIFEST.in│ README.rst│ setup.py│└─condition_chain core.py __init__.py __version__.py
Package upload
Run the following command under Setup.py's sibling directory.
python setup.py sdist bdist_wheel
And then run
twine upload dist/*
Note To enter the PyPI account number and password.
Done
After that we can search our own Python library in PyPI, and of course we can install it directly from PIP.
How to publish your own Python library on PyPI