Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to publish your open source project to a Pypi server

Shulou Source: shulou.com Published: 2022-06-01 11:58:07 10月01日 Update

This article mainly explains "how to publish your open source project to the Pypi server", the content of the article is simple and clear, easy to learn and understand, please follow the editor's ideas slowly in depth, together to study and learn "how to publish your open source project to the Pypi server"!

As we all know, one of the most attractive things about the Python community is that it provides a wealth of third-party libraries to which anyone can submit their own open source toolkits. If you want users to download and install them directly through the pip command, as developers, we can upload their own open source code to the Pypi server.

In addition to all the package directories of the project, the directory structure also has setup.py files and dependent package files, requirements.txt, and README description files.

| |-- MANIFEST.in |-- README.md |-- third-party package on which the requirements.txt # project depends |-- setup.cfg |-- setup.py # configuration file `- zhihu # package directory |-- _ _ init__.py |-- auth.py |-- error.py |-- main.py |-- models |

The setup.py file must contain the parameters specified in the setup function:

#-*-encoding: UTF-8-*-from setuptools import setup, find_packagesimport ioVERSION = '0.2.4'with io.open ("README.md", encoding='utf-8') as f: long_description = f.read () install_requires = open ("requirements.txt"). Readlines () setup (name= "zhihu", # pip installation name version=VERSION, # current version Each update uploaded to pypi needs to modify author= "liuzhijun", author_email= "lzjun567@gmail.com", url= "https://github.com/lzjun567/zhihu-api", keyworads=" zhihu ", description=" zhihu api from humans ", long_description=long_description, packages=find_packages (exclude= ('tests',' tests.*')), include_package_data=True, license='MIT License', classifiers= [], install_requires=install_requires,)

You can also download the code directly. After local installation and configuration through python settup.py install, you need to register your account https://pypi.python.org/pypi on the Pypi website.

Before uploading files, create a new file .pypirc in the current user directory of the system, as follows, and specify the user name and password:

[distutils] index-servers = pypi [pypi] username:xxxxpassword:xxxx

Start uploading:

Python setup.py register sdist bdist_egg upload

After the upload is successful, test the effect with pip install zhihu. Found that there was an error IOError: [Errno 2] No such file or directory: 'README.md', said that the README.md file could not be found. In fact, a step has been ignored here. You need to add the MANIFEST.in file to the project and enter the readme and requirement files:

Include README.mdinclude requirements.txt thank you for reading, the above is the content of "how to publish your open source project to the Pypi server", after the study of this article, I believe you have a deeper understanding of how to publish your open source project to the Pypi server, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File project server service project release content directory user learning code that is community third party configuration success well known middle finger code download function parameter Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Apple NVidia macOS Linux