如何在 install_requires 中指定版本范围(setuptools,distribute) [英] How to specify version ranges in install_requires (setuptools, distribute)

查看:173
本文介绍了如何在 install_requires 中指定版本范围(setuptools,distribute)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个依赖于特定版本范围的包,例如<代码>>= 0.5.0,<0.7.0.install_requires 选项中是否可以,如果可以,应该怎么做?

I want to make a package to depend the particular version range e.g. >= 0.5.0, < 0.7.0. Is it possible in install_requires option, and if so how should it be?

推荐答案

根据 文档,您的语法应该可以正常工作.文档指出:

According to the documentation, your syntax should work correctly. The documentation states that:

setuptoolspkg_resources 使用通用语法来指定项目所需的依赖项.此语法由项目的 PyPI 名称组成,可选后跟方括号中以逗号分隔的附加"列表,可选后跟以逗号分隔的版本说明符列表.版本说明符是运算符 <、>、<=、>=、== 或 != 之一,后跟版本标识符.

setuptools and pkg_resources use a common syntax for specifying a project's required dependencies. This syntax consists of a project's PyPI name, optionally followed by a comma-separated list of "extras" in square brackets, optionally followed by a comma-separated list of version specifiers. A version specifier is one of the operators <, >, <=, >=, == or !=, followed by a version identifier.

文档给出了一个简单的例子,如下所示:

The documentation gives a simple example like this:

docutils >= 0.3

# comment lines and \ continuations are allowed in requirement strings
BazSpam ==1.1, ==1.2, ==1.3, ==1.4, ==1.5, \
    ==1.6, ==1.7  # and so are line-end comments

为了扩展这一点,如果您希望您的包需要 docutils 大于 0.3 版但小于 0.5 版的版本,则可以使用以下代码:

To expand upon that, if you want your package to require a version of docutils greater than version 0.3 but less than version 0.5, code like this would work:

docutils >= 0.3, <=0.5

另外两个注释.

  1. 文档还指出冗余/重叠的依赖规范将在内部合并,因此 docutils >= 0.3, >=0.2 将合并为 docutils >= 0.3.
  2. 另外,请注意指定冲突的版本号,"没有意义,因此可能会产生奇怪的结果." 例如,我不知道你为什么会这样做,但不要使用这个:docutils >= 0.3, <=0.2 因为这是不可能的.
  1. The documentation also states that redundant/overlapping dependency specifications will be combined internally, so docutils >= 0.3, >=0.2 would be combined into docutils >= 0.3.
  2. Also, be careful about specifying conflicting version numbers, which "is meaningless and may therefore produce bizarre results." For example, I don't know why you would, but don't use this: docutils >= 0.3, <=0.2 since this is impossible.

这篇关于如何在 install_requires 中指定版本范围(setuptools,distribute)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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