Ananconda虚拟环境下安装tensorflow、spyder

创建虚拟环境:
conda create -n tf python==3.8.3

进入:
source activate tf

进入虚拟化环境之后,换源、安装tensorflow的gpu版(不然太慢了):
(加清华源)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

更新apt(好像不需要这一步):
sudo apt-get update

conda install tensorflow-gpu

试试是否安装成功:
python
import tensorflow as tf

安装spyder
conda install spyder

检查spyder里面能否顺利运行tensorflow:
import tensorflow as tf
tf.compat.v1.disable_eager_execution() #保证sess.run()能够正常运行
hello = tf.constant(‘hello,tensorflow’)
sess= tf.compat.v1.Session() #版本2.0的函数
print(sess.run(hello))

参考:
用的是虚拟化环境,每次需要先进入conda的虚拟环境再进入spyder,
https://blog.csdn.net/zbr794866300/article/details/97770752?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

在图形界面安装
https://blog.csdn.net/chenmaolin88/article/details/79370258?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

需要在虚拟环境里安装spyder和tensorflow,缺一不可。
使用命令打开图形界面,在environment里面搜索安装
anaconda-navigator

你可能感兴趣的:(anaconda,tensorflow,python,ubuntu)