1.在Anaconda Prompt中利用Anaconda创建一个python3.5的环境,环境名称为tensorflow ,输入下面命令:
conda create -n tf2.5.2 python=3.8
2.运行 开始菜单->Anaconda3—>Anaconda Navigator
,点击左侧的Environments
,可以看到tensorflow
的环境已经创建好了
3.在Anaconda Prompt中启动tensorflow环境:
activate tf2.5.2
4.更新pip
python -m pip install --upgrade pip
5.安装tensorflow
pip install tensorflow==2.5.2 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install -i https://pypi.douban.com/simple --trusted-host pypi.douban.com sklearn
6.验证安装是否成功
输入python
输入代码
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!') #初始化一个TensorFlow的常量
sess = tf.Session() #启动一个会话
print(sess.run(hello))
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello = tf.constant('Hello, TensorFlow!')
sess = tf.compat.v1.Session()
print(sess.run(hello))