可以选择pip方式安装不过在不管windows和linux,都推荐利用anaconda配置环境,避免很多莫名其妙的问题
一、安装anaconda3及python
1、wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
or 官网自行下载
or 此镜像下载
2、下载路径下执行:~:bash Anaconda3-5.2.0-Linux-x86_64.sh
3、一路yes、回车
4、看到提示信息“Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]”,输入no
5、重启terminal,环境配置在.bashrc,执行source ~/.bashrc应用配置即可
6、~:conda -V 验证版本
二、安装、配置、验证tensoflow
1、执行conda list可以看到此时没有安装tensorflow包
2、安装它 :~$ conda install tensorflow
再来,conda list,有了
3、验证tensoflow是否安装成功
1、添加tf环境: conda create -n tensorflow python=3.6
2、激活环境:source activate tensorflow
3、验证: python #进入python环境
4、按照百度的方法,是这样
import tensorflow as tf
hello = tf.constant('first tensorflow')
sess = tf.Session()
print (sess.run(hello))
但是ubuntu18.04下如果按照这个会由于tensorflow版本报几个错
所以我们改成这样
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('first tensorflow')
sess = tf.compat.v1.Session()
print (sess.run(hello))
一些报错如下:
1、只有tensorflow 1 有此接口
2、sess.run()不能正常运行
3、当需要退出python环境,即执行Ctrl+D或者输入quit()或者exit()即可
4、退出tensorflow环境,source deactivate