1.编写项目
这个你可以自定义一定要包含__init__.py这个源文件,这是一个这个源文件的例子:
def add(num:int,add_num:int)->int:
return num + add_num
2.准备项目的发布
1.注册PyPi账户
URL:PyPi官方站
在看到的页面点击“注册”或者“register”,然后根据给出的要求继续。
2.创建API Token
在会到的界面点击自己,找到账户设置,点击进去,下拉找到API Token,如图:

添加令牌后,不要退出,先把刚刚创建的API TOKEN复制到一个文本文档,以便记录。
然后安装twine,代码如下:
MacOS:
python3.exe -m pip3 install setuptools.twine
Windows:
py.exe -m pip install setuptools.twine
3.编写文件
1.setup.py 可以度娘一下,看看怎么写
2.LICENSE文件,如下列文本:
Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3.project.toml,如下:
[project]
name = ""
version = ""
authors = [
{ name="", email="" },
]
description = "Example"
readme = "readme.md"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
Homepage = "https://www.github.com/example/py-project"
Issues = ""
4.readme.md文件,这个你可以自定义
4.发布
WARNING:在此之前,请确保你已安装twine库
1.生成项目包
MacOS:
python3.exe -m build
Windows:
py.exe -m build
2.检查项目包
MacOS:
python3.exe -m twine check dist/*
Windows:
py.exe -m twine check dist/*
3.上传项目包
这时,就可以用到我们的api token了
MacOS:
python3.exe -m twine upload dist/*
Windows:
py.exe -m twine upload dist/*
恭喜,你的项目上传完毕了!
你可以检查一下安装是否成功
MacOS:
python3.exe -m pip install build
Windows:
py.exe -m pip install build
2877

被折叠的 条评论
为什么被折叠?



