Python包构建工具

1. 简介

Python 官方也提供了关于打包 Python 包的文档:

相对于官方提供的打包方式,一些第三方打包工具更加方便,比如 Poetry 等。

2. Poetry

Poetry 在构建 Python 包解决依赖时,可能需要下载依赖包。Poetry 默认是从 PyPI 官网下载,在国内由于众所周知的原因,下载比较慢,可以更换国内源:

1
2
3
4
5
豆瓣 https://pypi.doubanio.com/simple/
网易 https://mirrors.163.com/pypi/simple/
阿里云 https://mirrors.aliyun.com/pypi/simple/
腾讯云 https://mirrors.cloud.tencent.com/pypi/simple
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

具体方法为在 pyproject.toml 配置文件中增加下面的配置,以阿里云为例:

1
2
3
[[tool.poetry.source]]
name = "aliyun"
url = "https://mirrors.aliyun.com/pypi/simple/"