美文网首页
PyPI打包python library

PyPI打包python library

作者: Lyudmilalala | 来源:发表于2021-12-26 22:05 被阅读0次

打包流程

安装需要的工具

pip install --user --upgrade setuptools wheel twine

查看setuptools支持那些类型的包

python setup.py --help-commands

打包

python setup.py sdist bdist_wheel

sdist会打包成压缩的源码,如果不想给用户暴露源码,则不应执行sdist
bdist会打包成二进制文件,wheel是可以通过pip被安装的格式
打包的包会出现在当前路径下的dist文件夹里
在linux下直接打包会出现如example_pkg-0.0.1-cp39-cp39-linux1_x86_64.whl的wheel,直接上传到pypi会报错

HTTPError: 400 Client Error: Binary wheel 'example_pkg-0.0.1-cp39-cp39-linux_x86_64.whl' has an unsupported platform tag 'linux_x86_64'. for url: https://test.pypi.org/legacy/

因此需要指定platform name为manylinux1_x86_64

python setup.py bdist_wheel --plat-name=manylinux1_x86_64

为了维护资源的永久一致性,每个【包名】+【版本号】组合用就只能出现唯一一次,若和其他人已经上传的包冲突则无法成功上传。就算删除现存资源,也无法使用该【包名】+【版本号】组合。

先上传至测试平台,查看部署没有问题
平台地址: https://test.pypi.org/

twine upload --repository-url https://test.pypi.org/legacy/ dist/

再上传至真正的PyPI
平台地址: http://pypi.org/

twine upload dist/*

上传完成即可按照指示通过pip安装资源包

若有多个不同操作系统的包存在,pip会在安装时自动匹配对应的包,无法匹配则会报错

相关文章

网友评论

      本文标题:PyPI打包python library

      本文链接:https://www.haomeiwen.com/subject/aviifrtx.html