准备
查看当前的Python环境,ubuntu16.04默认的Python版本是2.7.12,使用python -V查看当前的python版本
1、安装pip
在终端输入命令:sudo apt-get install python-pip python-dev
2、安装tensorflow
在终端输入命令:pip install tensorflow
注意:执行完命令后发现安装开始执行,但网速慢的可怜,只有几kb每秒。需要把pip下载源改为国内的下载源。(如果能接受这网速,可以跳过下面修改pip下载源的步骤)
修改pip下载源的做法如下:
1、cd ~
2、mkdir .pip
3、sudo nano .pip/pip.conf
在pip.conf文件中添加如下内容:(我用的中科大的源)
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host = mirrors.ustc.com
还有一些其他的下载源,如下:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
3、验证tensorflow是否安装成功
进入python命令模式,输入如下代码,测试tensorflow:
import tensorflow as tf
sess = tf.Session()
hello=tf.constant('Hello,Tensorflow!')
print(sess.run(hello))
到这里,tensorflow就已经安装成功了!