打开Anaconda Prompt输入一下代码进行环境的安装配置:
conda create -n TF2.1 python-3.7
conda activate TF2.1
conda install cudatoolkit=10.1
conda install cudnn=7.6
pip install tensorflow==2.1
python //进入python
import tensorflow as tf
tf.__version__ //显示2.1.0表示安装成功
打开pycharm,点击NewProject
选择Existing interpreter,选择刚刚配置的TF2.1,点击create创建工程
新建一个python文件,输入一下代码,运行
import tensorflow as tf
tensorflow_version = tf.__version__
gpu_available = tf.test.is_gpu_available()
print("tensorflow version:",tensorflow_version,"\t GPU available:",gpu_available)
a = tf.constant([1.0,2.0],name="a")
b = tf.constant([1.0,2.0],name="b")
result = tf.add(a,b,name="add")
print(result)
显示:
tensorflow version: 2.1.0 GPU available: True
tf.Tensor([2. 4.], shape=(2,), dtype=float32)
表示开发环境已经安装成功