主要参考这个博客 打开anaconda prompt
输入下面命令。新建一个名为“tensorflow”的python环境
conda create -n tensorflow python=3.8
然后点y,开始安装
安装完成后,打开anaconda navigator
看到这是我们刚建的环境
输入下面内容,激活环境
activate tensorflow
开始给我们的TensorFlow环境装TensorFlow,先试试看cpu版本的,GPU以后再搞
pip install --upgrade --ignore-installed tensorflow
安装完毕
但是文章开头的那篇博客的hello world程序只能是tf1.x的,2.x得改程序 代码如下:
1.tf.constant里面是单引号
2.要在我们刚才新建的环境“TensorFlow”下做,如果不在环境下,就激活环境
activate tensorflow
python
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('Hello,world!')
sess = tf.compat.v1.Session()
print(sess.run(hello))
运行结果如下