ubuntu安装tensorflow(cpu版)教程

准备

在完成系统安装后,https://blog.csdn.net/woshigaowei5146/article/details/125411831?spm=1001.2014.3001.5501

下载anaconda:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

安装Anaconda3

下载好后,到下载路径。

bash Anaconda3-5.3.1-Linux-x86_64.sh

配置环境变量

sudo gedit ~/.bashrc

在最后一行中加入自己安装的anaconda下bin的路径:

#set Anaconda3 environment
export PATH="/home/zlt/anaconda3/bin:$PATH"

保存关闭文件后,使其生效:

source ~/.bashrc

输入python,验证。
在这里插入图片描述

安装Tensorflow

用conda新建一个python版本为3.6的虚拟环境。

conda create -n tensorflow python=3.6

激活虚拟环境

source activate tensorflow

安装tensorflow,注意没有GPU的不要装GPU版本,否则系统报错。

(tensorflow)$ pip install --ignore-installed --upgrade tfBinaryURL 

其中 tfBinaryURL 是 TensorFlow Python 包的 URL。例如,如下命令安装了仅支持 CPU 的 Python 3.4 版本下的 TensorFlow:

(tensorflow)$ pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp34-cp34m-linux_x86_64.whl 

我用的命令:

pip install --ignore-installed --upgrade \https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl

如果安装速度慢,可换源或下载好后安装。

tensorflow对应的python版本清单:

https://tensorflow.google.cn/install/source_windows#cpu

其他版本:

Python 2.7 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp27-none-linux_x86_64.whl
支持 GPU:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp27-none-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.4 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp34-cp34m-linux_x86_64.whl
支持 GPU:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp34-cp34m-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.5 支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp35-cp35m-linux_x86_64.whl
GPU 支持:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp35-cp35m-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.6 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
GPU 支持:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl

验证安装

先看看自己的tensorflow版本,可以看到我安装版本的是1.3.0

pip list

在这里插入图片描述
输入python来运行:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

参考

https://blog.csdn.net/elsa001/article/details/119150775
https://tensorflow.juejin.im/install/install_linux.html#toc-16

猜你喜欢

转载自blog.csdn.net/woshigaowei5146/article/details/125467792
今日推荐