分发需要最低 Python 版本的 Python 包的最佳方法是什么

发布于 2024-12-08 07:04:10 字数 634 浏览 0 评论 0原文

我有一个需要 Python 2.4 或更高版本的 Python 2 项目(“foo 0.1.7”)。

现在我将其移植到 Python 3('foo 0.2.0'),其方式仍然与 Python 2 兼容,但要求现在提升到 Python 2.6 或更高版本。

  • 我知道 setup.py 有一个 --target-version=2.6 选项,可以与 upload 一起使用,但这似乎并不意味着“2.6” 。
  • setup 命令有一个 install_requires 选项,但这是针对必需的包,而不是 Python 解释器

我可以在 'foo 0.2.0' 的 setup.py 中执行类似的操作:

if sys.hexversion < 0x02060000:
    raise RuntimeError('This package requires Python 2.6 or later, try foo 0.1.7')

但我更希望 easy_install foo 能以某种方式解决这个问题。

那么,我应该如何在 PyPI 上部署它呢?

I have a Python 2 project ('foo 0.1.7') that required Python 2.4 or later.

Now I ported it to Python 3 ('foo 0.2.0') in a way that it still is compatible with Python 2, but the requirements are now lifted to Python 2.6 or later.

  • I know that there is a --target-version=2.6 option for setup.py, that can be used with upload, but that seems not to be meant as '2.6 or higher'
  • The setup command has an install_requires option, but this is for required packages, .not Python interpreter.

I could do something like this in setup.py of 'foo 0.2.0':

if sys.hexversion < 0x02060000:
    raise RuntimeError('This package requires Python 2.6 or later, try foo 0.1.7')

but I would prefer if easy_install foo would resolve this in some way.

So, how should I deploy this on PyPI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-12-15 07:04:10

我知道 setup.py 有一个 --target-version=2.6 选项,可以是
与上传一起使用,但这似乎并不意味着“2.6 或更高版本”

它实际上是 bdist_wininst 或 bdist_msi 的一个选项,并且确实不包括“或更高版本”。

安装命令有一个 install_requires 选项,但这是必需的
包,不是 Python 解释器。

也许将 'Python >= 2.6' 放在 install_requires 中可能会起作用:Python 2.5 到 3.2 创建一个 Python-blahblah-pyXY.egg-info 文件,所以如果你幸运的话 easy_install 可能会发现要求得到满足。如果没有,它可能会尝试从 PyPI 下载,所以呃......

我可以在“foo 0.2.0”的 setup.py 中执行类似的操作:
如果 sys.hexversion < 0x02060000:
raise RuntimeError('此包需要 Python 2.6 或更高版本,请尝试 foo 0.1.7')

这实际上是当前常见的习惯用法。此外,使用“编程语言 :: Python :: XY”宝藏分类器将为人类提供信息(我不知道有任何工具使用该信息)。

短期内,还是有希望的。 Python 发行版元数据的规范已更新,最新版本确实包含一个需要特定 Python 版本的字段:http://www.python.org/dev/peps/pep-0345/#requires-python

关于工具支持:distutils 已冻结,不支持,setuptools可能或可能如果不添加支持,它的分支分发可能会获得支持,并且 distutils2/packaging 已经支持它。 distutils2 包含一个名为 pysetup 的基本安装程序,它应该尊重 Requires-Python 字段(如果没有,请向 bugs.python.org 报告)。

现在,要立即解决您的问题,您可以执行以下操作之一:
-声明你的项目只支持2.6+
- 2.4用户下载时需要固定版本的文档(例如pip install“foo==0.1.7”)

I know that there is a --target-version=2.6 option for setup.py, that can be
used with upload, but that seems not to be meant as '2.6 or higher'

It is actually an option for bdist_wininst or bdist_msi, and indeed does not include “or higher”.

The setup command has an install_requires option, but this is for required
packages, .not Python interpreter.

Maybe putting 'Python >= 2.6' in install_requires could work: Python 2.5 up to 3.2 create a Python-blahblah-pyXY.egg-info file, so if you’re lucky easy_install may find that the requirement is satisfied. If not it will probably try to download from PyPI, so uh...

I could do something like this in setup.py of 'foo 0.2.0':
if sys.hexversion < 0x02060000:
raise RuntimeError('This package requires Python 2.6 or later, try foo 0.1.7')

This is actually the current common idiom. In addition, using the “Programming Language :: Python :: X.Y” trove classifiers will give information for humans (I’m not aware of any tool using that info).

In the short-term future, there is hope. The specification for Python distributions metadata has been updated, and the latest version does contain a field to require a specific Python version: http://www.python.org/dev/peps/pep-0345/#requires-python

Regarding tool support: distutils is frozen and won’t support it, setuptools may or may not add support, its fork distribute will probably gain support, and distutils2/packaging already supports it. distutils2 includes a basic installer called pysetup, which should respect the Requires-Python field (if not, please report to bugs.python.org).

Now, to address your problem right now, you can do one of these things:
- declare that your project only supports 2.6+
- document that 2.4 users need to pin the version when downloading (e.g. pip install "foo==0.1.7")

葬花如无物 2024-12-15 07:04:10

听起来您正在寻找一种上传程序版本 0.1.7 和 0.2.0 的方法,并且让 easy_install-2.5 自动使用 0.1.7,而 easy_install-2.6 将使用 0.2.0。

如果是这种情况,我不确定是否可以与当前系统一起使用... raise RuntimeError() 检查可能是当前可用的最佳选项;安装您项目的人必须手动 easy_install-2.5 -U "proj<0.2" 或类似的操作。

也就是说,目前有一个专门的小组正在致力于用名为 packaging 的更新库替换 distutilssetuptools 等。这个新库结合了现有 distutils 增强库的功能以及许多其他改进。它计划包含在 Python 3.3 中,然后作为 distutils2 向后移植。

与您的问题特别相关的是,它包含对设置元数据的许多增强;包括一个 "requires_python" 选项,这似乎是量身定制的准确指出您想要的信息。但是,我不确定他们计划如何利用这些信息,以及它是否会导致新的安装系统表现得像您想要的那样。

我建议发帖到包装联谊会,致力于开发新系统的 google 小组,他们将能够提供有关 requires_python 应该如何工作的详细信息...并可能获得您想要的安装行为新系统的底层,如果看起来的话可行(并且尚未实现)。

What it sounds like you're looking for is a way to upload both version 0.1.7 and 0.2.0 of your program, and have easy_install-2.5 automatically use 0.1.7, while easy_install-2.6 would use 0.2.0.

If that's the case, I'm not sure if it's possible to do with the current system... the raise RuntimeError() check might be the best option currently available; people who install your project would then have to manually easy_install-2.5 -U "proj<0.2", or something similar.

That said, there's a dedicated group currently working to replace distutils, setuptools, etc with an updated library named packaging. This new library combines the features of the existing distutils enhancement libraries, as well as a host of other improvements. It's slated for inclusion in Python 3.3, and then to be backported as distutils2.

Of special relevance to your question, it contains many enhancements to the setup metadata; including a "requires_python" option, which seems tailor made to indicate exactly the information you want. However, I'm not sure how they plan to make use of this information, and if it will cause the new setup system to behave like you wanted.

I'd recommended posting to the fellowship of the packaging, the google group dedicated to the development of the new system, they would be able to give details about how requires_python is supposed to work... and possibly get the installation behavior you want in on the ground floor of the new system if it seems feasable (and isn't already there).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文