2016-06-28 103 views
2

我想要設置一個setup.py腳本爲install tensorflow,但不是簡單的pip install方法來安裝它。使用setuptools安裝tensorflow

我發現的唯一方法就是這種非常冒險的方式,有沒有更好的官方方式來做到這一點?

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, 
     }) 

回答

0

由於tensorflow 1.0,你可以

pip install tensorflow 
0

有兩個TF模式,你可以在安裝它,一個只運行在CPU和首先嚐試利用自己的GPU其他。

的TensorFlow Python包的URL將不斷更新,並可以在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:如果你在一個虛擬環境中安裝了它,你需要通過上面所說的「源文件」命令將其激活,激活環境