Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use requirements.txt to specify different package versions for different python 3 versions

Suppose I am using pip to install a package foo in Python 3. Now suppose that foo version 1.0 works great for Python 3.5 or lower, but breaks for Python 3.6 or higher. And suppose that foo version 2.0 works great for Python 3.6 or higher.

How can I specify in my requirements.txt that pip should install foo==2.0 if Python interpreter is 3.6 or higher, and foo==1.0 if Python interpreter is 3.5 or lower?

like image 917
charlesreid1 Avatar asked Mar 03 '23 22:03

charlesreid1


1 Answers

It realy easy. The solve is PEP 508 -- Dependency specification for Python Software Packages. You must use environment markers. This will allow you to specify different versions of packages for different python versions. For example:

foo==2.0;python_version>="3.6"
foo==1.0;python_version<"3.6"
like image 183
Andrey Leontyev Avatar answered Apr 06 '23 08:04

Andrey Leontyev