【问题标题】:How to specify tensorflow dependency in requirements.txt system-agnostic如何在 requirements.txt system-agnostic 中指定 tensorflow 依赖项
【发布时间】:2017-04-10 00:59:28
【问题描述】:

我在 requirements.txt 中指定了我的项目的依赖项。对于当前的 tensorflow,我必须指定 Google 提供的 whl。不幸的是,有一个separate wheel depending on many system configurations

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

为您提供 12 种不同的 whl 文件组合(实际上,只有 10 种)。在不同设备(Ubuntu、Mac)上工作时,有没有办法让我的 requirements.txt 文件在两个系统上工作?具体来说,我在 Mac 和 Ubuntu 上使用 Python 3.5.2。

【问题讨论】:

标签: python python-3.x tensorflow


【解决方案1】:

我认为如果您使用 setup.py 或 requirements.py 之类的文件会更好。在 python (.py) 文件中,您可以通过以下方式轻松获取操作系统信息:

import sys
sys.platform

您还可以通过以下方式触发任何终端命令来安装任何软件包:

import os
os.system("ls -a")

【讨论】:

    【解决方案2】:

    正如@sygi 在他的评论中所说,将要求限制在特定平台或 Python 版本的方法在 https://stackoverflow.com/a/35614580/1951176 中进行了描述。对于我们的 TensorFlow 示例,它会显示为

    # 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'
    

    最后,正如我刚刚发现的那样,在 TensorFlow 的特定情况下,它只需要指定

    tensorflow
    

    requirements.txt(与其他要求一样)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      相关资源
      最近更新 更多