How to post your own Python library and pypipython library on Pypi
Background
Recently, I have written several Python libraries and published them to Pypi. Although no one downloads them, It is very convenient to use them on other machines. Here I will introduce how to publish your own Python library on Pypi.
Prepare to register an account
Obviously, you need to register an account on Pypi.
Install necessary libraries setuptools
In principle, the environment where pip is installed has setuptools, but it does not affect your attempt to upgrade it.
pip install --upgrade setuptools
Twine
This is a tool that simplifies the process of publishing a database to Pypi.
pip install --upgrade setuptools
Clone repository (recommended)
The author of the well-known requests library, Jian threitz, has prepared a warehouse as a good template for setup. py. Of course, you can also write setup. py by yourself.
git clone https://github.com/kennethreitz/setup.py
Encoding edit setup. py
We recommend that you directly edit setup. py in the previous repository. You only need to modify some necessary configurations. This is the configuration of my recently compiled database condition_chain.
...# 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 = 'duyixian1234@outlook.com'AUTHOR = 'Yixian Du'# What packages are required for this module to be executed?REQUIRED = [ # 'requests', 'maya', 'records',]...
Write core code
Next we can write our own code. Note that the Name of the source code folder (the my_package folder in the repository) must be consistent with the package Name configured in setup. py.
In addition, we need to modify the version number in _ version _. py before re-Uploading, so as not to overwrite the previous upload (I believe someone will need the library of the previous version ).
Final code structure
│ LICENSE│ MANIFEST.in│ README.rst│ setup.py│└─condition_chain core.py __init__.py __version__.py
Package and upload
Run the following command in the directory of the same level as setup. py.
python setup.py sdist bdist_wheel
Then run
twine upload dist/*
Enter the Pypi account and password.
Success
Then we can search for our own Python library in Pypi. Of course, we can also install Python directly through pip.