pip3安装tensorflow

网上教程很多,当然官方也有,不过大部分地方都是用Python2来安装的,

这里是我自己总结的,尽量使用高版本的环境来安装

操作系统:Xubuntu17.04 64位

Python版本使用Python3.5

这里使用 pip3 安装,下次再介绍源码编译安装,对于初次接触的人来讲,还是pip3安装比较方便


1. 安装pip3,

sudo apt install python3-pip

2. 安装TensorFlow

sudo pip3 install tensorflow


等待片刻,TensorFlow安装完成


验证安装,执行命令如下:


$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2017-08-28 13:02:47.410873: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-28 13:02:47.410971: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-28 13:02:47.410990: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a+b))
42
>>> quit()

中间有打印一些告警信息,如果是使用源码编译方式安装的话,应该不会出现,而我们这里是使用pip3来安装的,所以对这些指令不支持


当然也可以创建一个文件hello_tensor.py,输入内容如下:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a+b))

然后执行命令

python3 hello_tensor.py


也会出现相同的打印结果


由于本人对Python语言也不熟悉,之前都是使用C语言的,所以如果有什么问题,请看到的诸位批评指正


你可能感兴趣的:(TensorFlow)