alex alex - 7 days ago 6
Python Question

How to specify tensorflow dependency in requirements.txt system-agnostic

I specify my project's dependencies in requirements.txt. For tensorflow currently I have to specify the whl provided by Google. Unfortunately, there is a separate wheel depending on many system configurations:

(Mac, Ubuntu) x (CPU, GPU) x (Python2.7, Python3.4, Python3.5)

giving you 12 different combinations of whl files (indeed, there are only 10). When working from different devices (Ubuntu, Mac), is there a way to have my requirements.txt file work on both systems? Specifically, I use Python 3.5.2 on Mac and Ubuntu.

Answer

As @sygi says in his comment, the way to restrict requirements to specific platforms or Python versions is described in http://stackoverflow.com/a/35614580/1951176. For our TensorFlow example, it would read

# Linux, Python 3.5
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl; sys_platform == 'linux' and python_version == '3.5'
# Linux, Python 3.4
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp34-cp34m-linux_x86_64.whl; sys_platform == 'linux' and python_version == '3.4'
# Linux, Python 2.7
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl; sys_platform == 'linux' and python_version == '2.7'
# Mac, Python 3.4 or 3.5
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl; sys_platform == 'darwin' and ( python_version == '3.4' or python_version == '3.5' )
# Mac, Python 2.7
https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py2-none-any.whl; sys_platform == 'darwin' and python_version == '2.7'

Finnally, as I just found out, in the specific case with TensorFlow, it works to specify just

tensorflow

in requirements.txt (as with other requirements).

Comments