【问题标题】:Install tensorflow using setuptools使用 setuptools 安装 tensorflow
【发布时间】:2016-06-28 06:53:41
【问题描述】:

我想为install tensorflow 设置一个setup.py 脚本,但没有简单的pip install 方法来安装它。

我想出的唯一方法是这种非常hacky的方法,有更好的官方方法吗?

from setuptools import setup
from setuptools.command.install import install

from subprocess import call
from sys import platform as _platform

#linux or ios
if _platform == "linux" or _platform == "linux2":
    tensorfow_url = "https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl"
elif _platform == "darwin":
    tensorfow_url = "https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl"


class CustomInstallCommands(install):
    """Installs tensorflow the hacky way"""

    def run(self):
        call(['pip', 'install', '--upgrade', tensorfow_url])
        install.run(self)


setup(name='tensorflow_project',
      version='0.1',
      description='project with tensorflow',
      packages=['tensorflow_project'],
      install_requires=[
          'scipy',
          'numpy',
          'pandas',
          'scikit-learn',

      ],
      zip_safe=False,
      cmdclass={
          'install': CustomInstallCommands,
          'develop': CustomInstallCommands,
      })

【问题讨论】:

    标签: python-2.7 tensorflow setuptools packaging


    【解决方案1】:

    从 tensorflow 1.0 开始,你就可以了

    pip install tensorflow
    

    【讨论】:

      【解决方案2】:

      您可以在两种 TF 模式中安装它,一种仅在 CPU 上运行,另一种尝试首先使用您的 GPU。

      TensorFlow Python包的网址会不断更新,可以在Installing TensorFlow on Ubuntu找到

      要安装,请按照此操作

      #(Optional step: you may also want to consider installing it in a Virtual environment)
      virtualenv  ~/tensorflow
      source ~/tensorflow/bin/activate
      

      然后设置最适合你的系统配置和版本需要的TF包对应的URL

      export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp27-none-linux_x86_64.whl 
      #(this is the cpu version)
      

      export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp27-none-linux_x86_64.whl 
      #(this is the gpu version)
      

      然后

      pip install --upgrade $TF_BINARY_URL
      

      PS:如果你是在虚拟环境中安装的,需要通过上面提到的“source”命令激活环境来激活它

      【讨论】:

        猜你喜欢
        • 2016-03-19
        • 2012-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-13
        • 2021-05-05
        • 1970-01-01
        相关资源
        最近更新 更多