当前位置:网站首页>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_description
The 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 check
appear
running check
Said 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.py
In 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
twine
pip 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 information
Wrong user authentication information , You need to create a user verification file
~/.pypirc
, See above -
Server response (401): Incomplete registration; check your email
Yours PyPI The account has not completed email verification yet
-
error: Upload failed (499): Client Disconnected
Network problems , Try again a few times
-
Upload failed (400): File already exists
The file already exists , Every upload should update the version number
Reference resources
版权声明
本文为[zzzzls~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220547251872.html
边栏推荐
- Making message board with PHP + MySQL
- 跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
- API slow interface analysis
- C language hash dictionary and notes
- Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
- Golang memory escape
- Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
- MySQL uses or to query SQL, and SQL execution is very slow
- Where, on when MySQL external connection is used
- [winui3] write an imitation Explorer file manager
猜你喜欢
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
[2021] Spatio-Temporal Graph Contrastive Learning
The WebService interface writes and publishes calls to the WebService interface (I)
Redis persistence
Deep learning notes - semantic segmentation and data sets
深度学习笔记 —— 物体检测和数据集 + 锚框
Nacos source code startup error report solution
源码剖析Redis中如何使用跳表的
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
随机推荐
Summary of R & D technology
Harmonious dormitory (linear DP / interval DP)
Interview summary
项目经理值得一试的思维方式:项目成功方程式
退出vim的方法
如何在Word中添加漂亮的代码块 | 很全的方法整理和比较
Barcode generation and decoding, QR code generation and decoding
深度学习笔记 —— 语义分割和数据集
Backup MySQL database with Navicat
The WebService interface writes and publishes calls to the WebService interface (2)
How to exit VIM
JS Array常见方法
A trinomial expression that causes a null pointer
Knowledge points sorting: ES6
独立站运营 | FaceBook营销神器——聊天机器人ManyChat
Golang select priority execution
[database] MySQL basic operation (basic operation ~)
Introduction to load balancing
calendar. Pit point of getactualmaximum (calendar. Day_of_month)
Informatics Aosai yibentong 1212: letters | openjudge 2.5 156: Letters