I'm trying to port a python2 package to python3 (not my own) using six so that it's compatible with both. However one of the packages listed in requirements.txt is now included in the python3 stdlib and the pypi version doesn't work in python3 so I want to conditionally exclude it. Doing this in setup.py is easy, I can just do something like:
if sys.version_info[0] == 2:
requirements += py2_requirements
else:
requirements += py3_requirements
But I would like requirements.txt to reflect the correct list too. I can't find anything on this in the pip documentation. so does anyone know how to do it, or if it is even possible?
You can use the environment markers to achieve this in
requirements.txt
sincepip 6.0
:It is supported by setuptools too by declaring extra requirements in
setup.py
:See also requirement specifiers.
You can create multiple requirements files, put those common packages in a common file, and include them in another pip requirements file with
-r file_path
python2.txt:
python3.txt:
pip install -r requirements/python2.txt
I don't think that it is possible because the requirements.txt file is just a text file. The closest thing I can think of would be to comment out the package in requirements.txt with a comment above stating that it should be installed for python2.6. Maybe it would be worth adding some code in to check the python version?
See my answer https://stackoverflow.com/a/25078063/302521 and this script: https://gist.github.com/pombredanne/72130ee6f202e89c13bb