分发需要最低 Python 版本的 Python 包的最佳方法是什么
我有一个需要 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 withupload
, but that seems not to be meant as '2.6 or higher' - The
setup
command has aninstall_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它实际上是 bdist_wininst 或 bdist_msi 的一个选项,并且确实不包括“或更高版本”。
也许将 'Python >= 2.6' 放在 install_requires 中可能会起作用:Python 2.5 到 3.2 创建一个 Python-blahblah-pyXY.egg-info 文件,所以如果你幸运的话 easy_install 可能会发现要求得到满足。如果没有,它可能会尝试从 PyPI 下载,所以呃......
这实际上是当前常见的习惯用法。此外,使用“编程语言 :: 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”)
It is actually an option for bdist_wininst or bdist_msi, and indeed does not include “or higher”.
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...
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")
听起来您正在寻找一种上传程序版本 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
的更新库替换distutils
、setuptools
等。这个新库结合了现有 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 manuallyeasy_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 namedpackaging
. 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 asdistutils2
.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).