作者: Morvan 编辑: Morvan
安装 Tensorflow 时需要注意的几点:
Tensorflow 的安装方式很多. 比如官网提供的:
这节内容使用 pip 在每个系统的安装方式:
本文将提到第一种最简单的安装方式, pip 安装.使用 pip 安装的时候要确保你的 pip 已经存在于你的电脑中. 如果还没有安装 pip. 你可以在 Terminal 窗口中运行这个:
# Ubuntu/Linux 64-位 系统的执行代码:$ sudo apt-get install python-pip python-dev# Mac OS X 系统的执行代码:$ sudo easy_install pip$ sudo easy_install --upgrade six
激动人心的时刻到了, Tensorflow (0.12) 刚刚做了更新, 绕过了复杂的安装步骤, 如果你只需要安装CPU 版本的 Tensorflow, 运行下面这个就好了:
# python 2+ 的用户:$ pip install tensorflow# python 3+ 的用户:$ pip3 install tensorflow
注意: 你需要8.1或更高版的 pip
才能顺利安装.
但是 如果你想安装 GPU 版的 Tensorflow, 你要在下面找一个适合你版本的安装文件, 并在 terminal 中执行:
# Ubuntu/Linux 64-bit, CPU only, Python 2.7$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc0-cp27-none-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.0rc0-cp27-none-linux_x86_64.whl# Mac OS X, CPU only, Python 2.7:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py2-none-any.whl# Mac OS X, GPU enabled, Python 2.7:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc0-py2-none-any.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.4$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.4# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.0rc0-cp34-cp34m-linux_x86_64.whl# Ubuntu/Linux 64-bit, CPU only, Python 3.5$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc0-cp35-cp35m-linux_x86_64.whl# Ubuntu/Linux 64-bit, GPU enabled, Python 3.5# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.0rc0-cp35-cp35m-linux_x86_64.whl# Mac OS X, CPU only, Python 3.4 or 3.5:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0rc0-py3-none-any.whl# Mac OS X, GPU enabled, Python 3.4 or 3.5:$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc0-py3-none-any.whl
最后, 根据自己的 python 版本, 在 terminal 中执行以下语句:
# 如果你是 Python 2, 请复制下面$ sudo pip install --upgrade $TF_BINARY_URL# 如果你是 Python 3, 请复制下面$ sudo pip3 install --upgrade $TF_BINARY_URL
tf 0.12 版的英文安装说明
安装前的检查:
接下来惊心动魄啦! 在 command 窗口中执行
# CPU 版的C:\> pip install tensorflow# GPU 版的C:\> pip install tensorflow-gpu
注意 Windows 运行 Tensorflow 如果遇到这个报错:
Error importing tensorflow. Unless you are using bazel,you should not try to import tensorflow from its source directory;please exit the tensorflow source tree, and relaunch your python interpreterfrom there.
不要惊慌, 尝试下载安装 Windows 的 Microsoft Visual C++ 2015 redistributable update 3 64 bit.就能解决这个问题.
然后打开你的 python 编辑器, 输入
import tensorflow
运行脚本来检查一下是否有正确安装.
最后, 如果你需要升级 Tensorflow 的版本, 推荐的方式是:
根据你的 python 版本, 在 terminal 中删除原有的版本
# 如果你是 Python 2, 请复制下面pip uninstall tensorflow# 如果你是 Python 3, 请复制下面pip3 uninstall tensorflow
然后重复这个安装教程的步骤, 从头安装新版本.
联系客服