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

Viewed 141

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'
    ]
)

I.e. 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?

1 Answers

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"',
    ]
)

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

Related