简体   繁体   中英

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 ).

To be specific, this is what I want to be able to do in my setup.py file:

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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