打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
1.2 安装TensorFlow
有安装视频介绍

安装

作者: Morvan    编辑: Morvan   

  • 学习资料:
    • 官方关于 Tensorflow 安装的 说明

安装 Tensorflow 时需要注意的几点:

  1. MacOS, Linux, Windows 系统均已支持 Tensorflow
  2. 确定你的 python 版本
  3. 你的 GPU 是 NVIDIA, 就可以安装 GPU 版本的 Tensorflow; 你的 GPU 不是 NVIDIA 也没有关系, 安装 CPU 版本的就好了.

安装 Tensorflow

Tensorflow 的安装方式很多. 比如官网提供的:

这节内容使用 pip 在每个系统的安装方式:

Linux 和 MacOS

本文将提到第一种最简单的安装方式, 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
CPU 版

激动人心的时刻到了, Tensorflow (0.12) 刚刚做了更新, 绕过了复杂的安装步骤, 如果你只需要安装CPU 版本的 Tensorflow, 运行下面这个就好了:

# python 2+ 的用户:$ pip install tensorflow# python 3+ 的用户:$ pip3 install tensorflow

注意: 你需要8.1或更高版的 pip 才能顺利安装.

GPU 版

但是 如果你想安装 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

Windows

tf 0.12 版的英文安装说明

安装前的检查:

  • 目前只支持 Python 3.5 (64bit) 版本
  • 你有安装 numpy (没有的话,请看这里numpy 安装教程)

接下来惊心动魄啦! 在 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

最后, 如果你需要升级 Tensorflow 的版本, 推荐的方式是:

根据你的 python 版本, 在 terminal 中删除原有的版本

# 如果你是 Python 2, 请复制下面pip uninstall tensorflow# 如果你是 Python 3, 请复制下面pip3 uninstall tensorflow

然后重复这个安装教程的步骤, 从头安装新版本.


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
win10下基于python(anaconda)安装gpu版本的TensorFlow以及kears深度学习框架
win10+Tensorflow+GPU详细的安装过程
TensorFlow在windows上安装与简单示例
在ubuntu18.04下安装tensorflow图形化jupyter notebook
Python系列-人工智能篇:带你搞懂TensorFlow基础入门
tensorflow的Virtualenv安装方式安装
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服