需求1:在win11指定文件夹中安装torch环境,
torch需求版本见官网,受CUDA版本限制,详见torch.org
默认已经安装 Anaconda3,可以使用conda指令
1.在指定 文件夹下进入cmd(或在CMD中CD到指定文件夹)
2.在CMD中用conda指令创建环境(环境名为env_name),并指定Python版本:
conda create -n env_name python=3.x
3.直接克隆环境
conda create -n 新环境名 --clone 旧环境名
3.进入创建的环境:
conda activate env_name
4.在该环境下安装torch包,此处指令参照torch.org官网:
如CUDA版本为11.1以上,则可安装torch1.8GPU版:
# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
5.安装完成后在Pycharm中添加该环境的路径,路径地址如:
“D:\Software\Anaconda3\envs\tf\python.exe”
备注:
在CMD退出环境:conda deactivate
删除环境:conda remove -n env_name --all
环境测试:
import torch
print("torch版本号:", end="")
print(torch.__version__)
print("判断torch是否可用:", end="")
print(torch.cuda.is_available())
print("gpu数量:", end="")
print(torch.cuda.device_count())
print("gpu名字,设备索引默认从0开始:", end="")
print(torch.cuda.get_device_name(0))
print("现在正在使用的GPU编号:", end="")
print(torch.cuda.current_device())
------------------------我是分割线-------------------------------------
需求2:在win11安装tf-gpu版本
1.用conda创建虚拟环境,同时指定Python版本:
#Python版本要求与tf版本相对应
#详见tf官网:https://tensorflow.google.cn/install/source_windows#gpu
conda create -n tf1.14 python=3.7
2.查看有哪些版本可以安装:
conda search tensorflow-gpu
3.在创建的虚拟环境中安装TensorFlow-GPU版:
conda install tensorflow-gpu==1.14.0
import tensorflow as tf
print(tf.__version__)
print(tf.__path__)
print(tf.__operators__)
print(tf.config.list_physical_devices('GPU'))