当前位置:网站首页>Publish your own wheel - pypi packaging upload practice
Publish your own wheel - pypi packaging upload practice
2022-04-23 05:14:00 【zzzzls~】
List of articles
As a popular programming language ,Python With the world's leading developer community , So that we can share and collaborate effectively . As the saying goes “ Life is too short , I use Python”,Python One of the advantages of is that it has rich and easy-to-use third-party modules . Whatever you do , You can almost always find expansion packs to achieve your goal . And all this , They are completely open source and free !

since Python The core of is the third-party expansion package , So do you want to write one and publish it yourself ? Whether you open source your excellent projects , Or write some gadgets that can be reused often , It's a great thing
Release Python package
PyPI(Python Package Index) Is an open source licensed public repository of software packages , Available for all Python The user to use .Python Package management tools pip, It's from PyPI Download the source code and compile the installed . If you want your package to be able to install over the network , that PyPI It's your choice

Get ready
- Go to PyPI Register the account on the official website and verify the email address
- Use Github hosting project ( Optional )
Create user authentication file
establish .pypirc file , Put it into the operating system ~ Under the table of contents , In the class linux In the system is ~/ Catalog ,windows Next is C:\Users\< user name >\, The contents are as follows :
[distutils]
index-servers = pypi
[pypi]
username: Yours PyPi user name
password: Yours PyPi password
Create project structure
zzzzls-project/
loler-spider/ # This bag is our Python The main document of the project
__init__.py
heroSpider.py
setup.py # setup.py, LICENSE, README.md It is the auxiliary file we want to package and release
LICENSE
README.md
To write setup.py
Let's focus on setup.py file , Because the entire pip The release and upload of the project are based on this file
import setuptools
with open("README.md", "r", encoding='utf-8') as fh:
long_description = fh.read()
setuptools.setup(
name="loler-spider",
version="1.0.1",
author="zzzzls",
author_email="[email protected]",
description="A spider to download lol-hero image",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/zzzzls/",
packages=setuptools.find_packages(),
license='MIT',
keywords=['lol', 'image', 'spider', 'download'],
install_requires=[
"requests",
"tqdm"
]
)
-
name
The release name of the package . Only by
Letter , Numbers , Underline (_), Horizontal bar (-), Period (.)constitute , Case insensitive , Need to ensure its uniqueness , Cannot have the same name as other packages . -
version
The version of the package . The subsequent updated software package needs to be modified to a higher version number
-
author & author_email
The author information
-
description
A brief description of the software package
-
long_description
Detailed description of the software package
-
long_description_content_type
Set up
long_descriptionThe text type of , It can betext/plain,text/x-rst,text/markdown -
url
Project home page URL, Here it points to Github Project address
-
packages
List of project packages , We can use
find_packages()To automatically discover all packages and sub packages . In the current project , The list of packages will beloler-spider -
license
Project license , See description below
-
keywords
Keywords of the project
-
install_requires
Other dependencies required for package operation , User pass pip When installing the current package , These dependencies are automatically installed
testing setup.py Whether the file syntax is correct
python setup.py checkappear
running checkSaid right , You can take the next step
More parameter Introduction :https://packaging.python.org/guides/distributing-packages-using-setuptools/
To write README.md
Description document on the front page of the project , The following is a basic example :
# Example Package
This is a simple example package. You can use
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
to write your content.
It is suggested to refer to the writing method of excellent projects , Example :requests
To write LICENSE
Here's a list 5 One of the most commonly used open source protocols (BSD, MIT, Apache2.0, GNU GPL, LGPL) And their scope of application , For developers who are ready to open source or use open source products / Manufacturer's reference

When you decide which protocol to use , Go to choosealicense Copy the corresponding agreement and paste it into LICENSE File can
Be careful : Need to synchronize changes
setup.pyIn file license Field !
Generate release package
python setup.py sdist bdist_wheel
Directory structure after correct execution :
├── build
│ ├── bdist.win-amd64
│ └── lib
│ └── loler_spider
│ ├── __init__.py
│ ├── HeroSpider.py
├── dist
│ ├── loler_spider-1.0.1-py3-none-any.whl
│ └── loler_spider-1.0.1.tar.gz
├── loler_spider
│ ├── __init__.py
│ ├── HeroSpider.py
├── loler_spider.egg-info
│ ├── dependency_links.txt
│ ├── PKG-INFO
│ ├── requires.txt
│ ├── SOURCES.txt
│ └── top_level.txt
├── LICENSE
├── README.md
└── setup.py
Local testing ( Optional )
It is recommended to upload the package to PyPI Complete the test locally before , The way is to enter dist Folder , And then use pip Command to install the local binary package , After installation, test whether the methods are available
cd dist
pip install loler_spider-1.0.1.tar.gz
Upload to PyPI
-
Install tools required for publishing
twinepip install twine -
Start uploading
twine upload dist/* -
The upload is successful when the following results appear

Visit... In the figure above URL You can reach the project PyPI Home page

Install the test
pip install loler-spider
It will take some time for domestic source collection , If the installation fails, it is recommended to use the official source for installation test
pip install loler-spider -i https://pypi.python.org/simple
Common mistakes
-
Upload failed (403): Invalid or non-existent authentication informationWrong user authentication information , You need to create a user verification file
~/.pypirc, See above -
Server response (401): Incomplete registration; check your emailYours PyPI The account has not completed email verification yet
-
error: Upload failed (499): Client DisconnectedNetwork problems , Try again a few times
-
Upload failed (400): File already existsThe file already exists , Every upload should update the version number
Reference resources
版权声明
本文为[zzzzls~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220547251872.html
边栏推荐
- The WebService interface writes and publishes calls to the WebService interface (I)
- A trinomial expression that causes a null pointer
- Barcode generation and decoding, QR code generation and decoding
- 5 minutes to understand MySQL row column conversion
- In aggregated query without group by, expression 1 of select list contains nonaggregated column
- Deep learning notes - semantic segmentation and data sets
- 静态流水线和动态流水线的区别认识
- Chapter I overall project management of information system project manager summary
- Tensorflow realizes web face login system
- TypeError: ‘Collection‘ object is not callable. If you meant to call the ......
猜你喜欢

Restful toolkit of idea plug-in

4 个最常见的自动化测试挑战及应对措施

看板快速启动指南

Details related to fingerprint payment
![[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength](/img/94/37d80984fe6fad84e73c2f8e6b2d52.jpg)
[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength

Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key

Making message board with PHP + MySQL

引入精益管理方式,需要提前做到这九点

Flip coin (Blue Bridge Cup)

2021 年 25 大 DevOps 工具(下)
随机推荐
The 8 diagrams let you see the execution sequence of async / await and promise step by step
Summary of MySQL knowledge points
2022年最热门的招聘技术技能是什么,您绝对想不到
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
calendar. Pit point of getactualmaximum (calendar. Day_of_month)
Musk and twitter storm drama
MySQL uses or to query SQL, and SQL execution is very slow
A trinomial expression that causes a null pointer
洛谷P2731骑马修栅栏
源码剖析Redis中如何使用跳表的
Interesting prime number problem hdu5750
MySQL foreign key constraint
[2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
Jupyter notebook crawling web pages
Interview summary
mysql5. 7. X data authorization leads to 1141
[WinUI3]编写一个仿Explorer文件管理器
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
What are instruction cycles, machine cycles, and clock cycles?
Redis lost key and bigkey