使用 setuptools 安装 tensorflow
Install tensorflow using setuptools
我想为 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,
})
从 tensorflow 1.0 开始,你可以
pip install tensorflow
有两种 TF 模式可供您安装,一种仅在 CPU 上运行,另一种尝试首先使用您的 GPU。
TensorFlowPython包的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
然后设置URL对应最适合你的系统配置和版本需要的TF包
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: 如果你是在Virtual环境下安装的,需要通过上面提到的"source"命令来激活环境
我想为 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,
})
从 tensorflow 1.0 开始,你可以
pip install tensorflow
有两种 TF 模式可供您安装,一种仅在 CPU 上运行,另一种尝试首先使用您的 GPU。
TensorFlowPython包的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
然后设置URL对应最适合你的系统配置和版本需要的TF包
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: 如果你是在Virtual环境下安装的,需要通过上面提到的"source"命令来激活环境