内容概要:
先分别创建cpu和gpu虚拟环境,激活虚拟环境,然后安装想要的版本。
1.安装CPU环境的tensorflow
1.1 创建虚拟环境
conda create -n tf2_cpu python=3.7.6
1.2 激活虚拟环境并指定安装tensorflow2.1版本
conda activate tf2_cpu
pip install tensorflow==2.1
1.3 验证安装成功(不报错)
2.安装GPU环境的tensorflow
conda 安装将自动安装 GPU 支持所需的 CUDA 和 CuDNN 库。
2.1 创建虚拟环境
conda create -n tf2_gpu python=3.7.6
2.2 激活gpu环境并安装tensorflow-gpu
conda activate tf2_gpu
conda install tensorflow-gpu #默认安装最新版本
2.3 验证安装成功
tf.test.is_gpu_available()#最后是True
tf.config.list_physical_devices('GPU')#[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
如果使用pip安装,需要配置CUDA和CUDNN,tensorflow与两者版本的对应关系,小伙伴可以自己查找,并对应下载tensorflow的版本。