setup.py's install_requires – how do I specify python version range for a specific dependency?

Question:

I’m working on a python project and the package supports python 3.6 – 3.10.

There were these 2 lines in the install_requires list in setup.py:

        "numpy>=1.18.5, <=1.19.5; python_version=='3.6'",
        "numpy>=1.19.5; python_version>='3.7'",

And I tried to change them to

        "numpy>=1.18.5, <=1.19.5; python_version=='3.6'",
        "numpy>=1.23.1; python_version>='3.10'",
        "numpy>=1.19.5; python_version>='3.7', <'3.10'",

And when I ran python setup.py install, I got this error:

$ python setup.py install
# yeah, I know `pip install .` is a better command.

error in mypackage setup command: 'install_requires' must be a 
string or list of strings containing valid project/version requirement specifiers; Parse error at "", <'3.10"": Expected string_end

I tried some different variants to specify a python_version range of 3.7 to 3.9, but none of them worked.

So how do I specify python version range for a specific dependency in setup.py?

Asked By: Teddy C

||

Answers:

Referring to Complete Grammar, you can use and to achieve your purpose.

"numpy>=1.18.5, <=1.19.5; python_version=='3.6'",
"numpy>=1.23.1; python_version>='3.10'",
"numpy>=1.19.5; python_version>='3.7' and python_version<'3.10'",
Answered By: Calvin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.