当前位置:网站首页>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
边栏推荐
- Knowledge points sorting: ES6
- Logrus set log format and output function name
- [2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
- [untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength
- [2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
- This call when the transaction does not take effect
- [database] MySQL multi table query (I)
- 深度学习笔记 —— 语义分割和数据集
- Barcode generation and decoding, QR code generation and decoding
- 2022年最热门的招聘技术技能是什么,您绝对想不到
猜你喜欢
Basic theory of Flink
The WebService interface writes and publishes calls to the WebService interface (2)
深度学习笔记 —— 语义分割和数据集
Where, on when MySQL external connection is used
项目经理值得一试的思维方式:项目成功方程式
5 minutes to understand MySQL row column conversion
Deep learning notes - semantic segmentation and data sets
直播带货表格模板-自动显示图片-自动关联系列商品
深度学习笔记 —— 物体检测和数据集 + 锚框
2022/4/22
随机推荐
Introduction to load balancing
A trinomial expression that causes a null pointer
多线程基本概念(并发与并行、线程与进程)和入门案例
MySQL memo (for your own query)
[database] MySQL single table query
学习笔记:Unity CustomSRP-11-Post Processing---Bloom
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
On distributed lock
7-4 is it too fat (10 points) PTA
The concept of meta universe is popular. Is virtual real estate worth investing
Details related to fingerprint payment
How can continuous integration (CI) / continuous delivery (CD) revolutionize automated testing
The difference between static pipeline and dynamic pipeline
深度学习笔记 —— 微调
深度学习笔记 —— 数据增广
What are instruction cycles, machine cycles, and clock cycles?
mysql5. 7. X data authorization leads to 1141
跨境电商 | Facebook 和 Instagram:哪个社交媒体更适合你?
MySQL slow query
2022/4/22