如何为 Python 2 和 3 上传通用 Python Wheel? [英] How do I upload a Universal Python Wheel for Python 2 and 3?

查看:83
本文介绍了如何为 Python 2 和 3 上传通用 Python Wheel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PyPi 上有一个包,在准备新版本时,我构建源代码分发版、构建轮子并上传,所有这些都使用 setuptools.

但是,我发现它只上传上传命令(pythonpython3)中使用的 Python 版本的轮子.

以下是我正在采取的步骤:

python3 setup.py sdistpython3 setup.py bdist_wheel --universalpython3 setup.py sdist bdist_wheel 上传

根据 Python 打包用户指南:><块引用>

Universal Wheels"是纯 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 的一个.

解决方案

命令 python3 setup.py sdist bdist_wheel upload 创建一个轮分布.

您需要在该命令行中再次包含相同的标志:

python3 setup.py sdist bdist_wheel --通用上传

最好使用 twine 来管理上传;它将使用加密连接(setuptools 使用未加密连接,因此会以明文形式发送您的用户名和密码),它允许您在上传之前检查和测试分发:

python3 setup.py sdistpython3 setup.py bdist_wheel --universal# 测试分布麻线上传dist/*

Twine 目前也是唯一一种为万向轮正确设置 PyPI 的Py 版本"元数据.

I have a package on PyPi and when preparing a new release I build the source distribution, build the wheel and upload, all with setuptools.

However, I've found it only uploads the wheel for the Python version used in the upload command (python and python3).

Here are the steps I'm taking:

python3 setup.py sdist
python3 setup.py bdist_wheel --universal
python3 setup.py sdist bdist_wheel upload

According to the Python Packaging User Guide:

"Universal Wheels" are wheels that are pure python (i.e. contains no compiled extensions) and support Python 2 and 3

So that seems to be the right thing for me.

After the wheel build step, I verify the wheel is built and has the filename format PACKAGE-VERSION-py2.py3-none-any.whl in dist but when I run the upload with python3 setup.py sdist bdist_wheel upload, it creates a PACKAGE-VERSION-py3-none-any.whl and uploads that.

If I run python setup.py sdist bdist_wheel upload it does the same for and uploads a Python 2-only one.

解决方案

The command python3 setup.py sdist bdist_wheel upload creates a new wheel distribution.

You'll need to include the same flags again on that command line:

python3 setup.py sdist bdist_wheel --universal upload

It's better to use twine to manage the uploads; it'll use an encrypted connection (setuptools uses an unencrypted connection and thus sends your username and password in the clear) and it allows you to inspect and test the distribution before uploading:

python3 setup.py sdist
python3 setup.py bdist_wheel --universal
# test the distributions
twine upload dist/*

Twine is currently also the only tool that sets the 'Py versions' metadata for PyPI correctly for universal wheels.

这篇关于如何为 Python 2 和 3 上传通用 Python Wheel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆