How to post your own Python library and pypipython library on Pypi

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.