简体   繁体   English

Python setup.py 依赖语法,package 的多个环境标记?

[英]Python setup.py dependency syntax, multiple environment markers for a package?

I don't entirely understand what sort of flexibility I have with regard to the use of environment markers ( https://www.python.org/dev/peps/pep-0508/#environment-markers ).我不完全了解我在使用环境标记( https://www.python.org/dev/peps/pep-0508/#environment-markers )方面有什么样的灵活性。

To be specific, this is what I want to be able to do in my setup.py file:具体来说,这是我希望在setup.py文件中能够做到的:

setup(
    ...
    install_requires=[
        'numpy>=1.8.1;python_version<2.7, >=3.0;python_version>3.6'
    ]
)

Ie suppose I want numpy>=1.8.1 if installing in Python 2, but I want >=3.0 if installing in Python>3.6.即假设如果在 Python 2 中安装,我想要 numpy>=1.8.1,但如果在 Python>3.6 中安装,我想要 >=3.0。 Is this sort of specification possible, and if so did I get the syntax correct?这种规范是否可能,如果可以,我的语法是否正确?

Well I still can't find this clearly explained anywhere, but from my experiments it seems like the following syntax does the job:好吧,我仍然无法在任何地方找到清楚的解释,但从我的实验看来,以下语法似乎可以完成这项工作:

setup(
    ...
    install_requires=[
        'numpy>=1.8.1; python_version<"2.7"', 
        'numpy>=3.0; python_version>"3.6"',
    ]
)

ie you can only specify one environment marker for the whole entry it seems, not attach them to a version number.即您只能为整个条目指定一个环境标记,而不是将它们附加到版本号。 But looks like just having separate entries works.但看起来只是有单独的条目有效。

Note also that the python version string must be enclosed in quotes, even though that doesn't seem to be necessary for the package version numbers.另请注意,python 版本字符串必须用引号引起来,即使 package 版本号似乎不需要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM