如何把一个 Python 项目发布到 PyPI 上指南教程 All In One
如何发布一个 Python 项目到 PyPI 上
如何发布一个 Python 包到 PyPI 上
https://pypi.org/user/xgqfrms/
官方文档
Packaging Python Projects
打包
Python 项目
https://packaging.python.org/en/latest/tutorials/packaging-projects/
https://packaging.python.org/distributing/
1. 安装工具
pip, 类似 Node.js 生态的 npm 功能
# 更新 pip
$ python3 -m pip install --upgrade pip
https://packaging.python.org/en/latest/key_projects/#pip
pip
is the package installer
for Python.
You can use it to install packages from the Python Package Index
and other indexes.
https://pip.pypa.io/en/stable/
https://pip.pypa.io/en/stable/getting-started/
https://pip.pypa.io/en/stable/installation/
2. 开发项目
项目代码结构树
# tree
$ tree packaging_tutorial
packaging_tutorial/
├── LICENSE
├── pyproject.toml
├── README.md
├── src/
│ └── example_package_YOUR_USERNAME_HERE/
│ ├── __init__.py
│ └── example.py
└── tests/
TODO:
https://github.com/xgqfrms/first_python_package_project
3. 构建项目
Generating distribution archives
生成分发档案
$ python3 -m pip install --upgrade build
$ python3 -m build
4. 发布项目
Uploading the distribution archives
上传分发档案
$ python3 -m pip install --upgrade twine
$ python3 -m twine upload --repository testpypi dist/*
PyPI
API token
https://test.pypi.org/help/#apitoken
5. 安装项目
$ python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps example-package-YOUR-USERNAME-HERE
6. 测试项目
# import the package in the REPL
$ python3
> from example_package_YOUR_USERNAME_HERE import example
> example.add_one(2)
3
issues
https://github.com/pypa/packaging-problems