如何为 Python 2 和 3 上传通用 Python Wheel?
Posted
技术标签:
【中文标题】如何为 Python 2 和 3 上传通用 Python Wheel?【英文标题】:How do I upload a Universal Python Wheel for Python 2 and 3? 【发布时间】:2015-08-06 22:15:09 【问题描述】:我在 PyPi 上有一个包,在准备新版本时,我构建源代码分发、构建***并上传,所有这些都使用 setuptools。
但是,我发现它只上传上传命令中使用的 Python 版本的***(python
和 python3
)。
以下是我正在采取的步骤:
python3 setup.py sdist
python3 setup.py bdist_wheel --universal
python3 setup.py sdist bdist_wheel upload
根据Python Packaging User Guide:
“通用***”是纯 Python 的***(即不包含已编译的扩展)并支持 Python 2 和 3
所以这对我来说似乎是正确的。
在***构建步骤之后,我验证***已经构建并且文件名格式为dist
中的PACKAGE-VERSION-py2.py3-none-any.whl
,但是当我使用python3 setup.py sdist bdist_wheel upload
运行上传时,它会创建一个PACKAGE-VERSION-py3-none-any.whl
并上传。
如果我运行 python setup.py sdist bdist_wheel upload
,它会执行相同的操作并上传仅 Python 2 的版本。
【问题讨论】:
【参考方案1】:命令python3 setup.py sdist bdist_wheel upload
创建一个新轮分布。
您需要在该命令行中再次包含相同的标志:
python3 setup.py sdist bdist_wheel --universal upload
最好使用twine
来管理上传;它将使用加密连接(setuptools
使用未加密连接,因此以明文形式发送您的用户名和密码)并允许您在上传之前检查和测试分发:
python3 setup.py sdist
python3 setup.py bdist_wheel --universal
# test the distributions
twine upload dist/*
Twine 目前也是 sets the 'Py versions' metadata for PyPI correctly for universal wheels 唯一的工具。
【讨论】:
以上是关于如何为 Python 2 和 3 上传通用 Python Wheel?的主要内容,如果未能解决你的问题,请参考以下文章
如何为在 64 位 Amazon Linux 2 上运行的 Elastic Beanstalk Python 3.7 项目安装节点包?