Anaconda安装
安装程序中记得选择添加到环境变量
Anaconda虚拟环境配置
- 在Anaconda Prompt中输入:
conda create -n tf python=X.X.X
python版本根据需要选择,这里选择的是python3.7版本。运行后输入y
进行安装
配置CUDA
-
激活虚拟环境:
在Anaconda Prompt中输入:
conda activate tf
-
英伟达显卡安装Geforce Experience,在Anaconda Prompt中输入:
nvidia-smi
得到版本信息,图片中的CUDA Version:11.7是指这个驱动最高支持11.7版本
-
根据CUDA Version配置cudatoolkit和cudnn
- 先卸载已有版本
conda uninstall cudnn
conda uninstall cudatoolkit
- 安装需要版本
- 搜多可安装版本:
conda search cudatoolkit
- 安装需要版本:
conda install cudatoolkit=X.X
conda install cudnn
- 搜多可安装版本:
- 先卸载已有版本
安装Tensorflow GPU
- 搜索可用的tensorflow-gpu版本
conda search tensorflow-gpu
输出:
某文章说python3.7对应的tensorflow-gpu版本为2.1Loading channels: done # Name Version Build Channel tensorflow-gpu 1.1.0 np112py35_0 anaconda/pkgs/free tensorflow-gpu 1.1.0 np112py36_0 anaconda/pkgs/free tensorflow-gpu 1.8.0 h21ff451_0 anaconda/pkgs/main tensorflow-gpu 1.9.0 hf154084_0 anaconda/pkgs/main tensorflow-gpu 1.10.0 hf154084_0 anaconda/pkgs/main tensorflow-gpu 1.11.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 1.12.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 1.13.1 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 1.14.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 1.15.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 2.0.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 2.1.0 h0d30ee6_0 anaconda/pkgs/main tensorflow-gpu 2.3.0 he13fc11_0 anaconda/pkgs/main tensorflow-gpu 2.5.0 h17022bd_0 anaconda/pkgs/main tensorflow-gpu 2.6.0 h17022bd_0 anaconda/pkgs/main
- 在Anaconda Prompt中输入:
conda install tensorflow-gpu==2.1.0
运行。输入y
进行安装
配置jupyter notebook
经尝试发现,虚拟环境安装好后,jupyter notebook无法打开新建虚拟环境,主要是因为缺少nb_conda包和tornado版本过高问题。
先要在base环境下安装nb_conda包,然后再在虚拟环境中安装nb_conda包
- 安装
nb_conda
conda install nb_conda
运行后输入y
执行 - 关于
tornado
包降级安装- 首先
pip list
查看现有版本 pip uninstall tornado
运行,输入y
执行卸载现有版本- 安装6.1版本(现尝试的可行版本,如有更好可自行选择)
pip install tornado==6.1
如果报红,可在卸载当前版本的基础上根据提示版本进行上述安装 - 重新在端输入
jupyter notebook
- 首先
检查 是否安装成功
- 进入虚拟环境中的python编译器
- 输入
import tensorflow as tf print('Tensorflow Version:{}'.format(tf.__version__)) # 打印版本信息 gpus = tf.config.experimental.list_physical_devices(device_type='GPU') # 读取可用GPU信息 print(gpus) # 打印可用GPU信息