赞
踩
打开Anaconda官网下载,看到是Python3.9,需要的版本比这个版本低,不过无所谓,可以后续单独配置环境。Anaconda安装完成后,先配置一下清华大学镜像,打开Anaconda的控制台:
conda配置清华源
# Windows 先执行 `conda config --set show_channel_urls yes` 生成 .condarc 的文件 #(在C:\Users\目录下) : # 建议直接去清华镜像站看最新的镜像地址,也可以使用下方提供的配置: # https://mirror.tuna.tsinghua.edu.cn/help/anaconda/ # 复制到.condarc文件: channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud # Conda查看当前源: conda config --show-sources
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
使用pip指定清华源与安装requirements的指令
# pip配置镜像 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 安装requirements pip install -r XXX\requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
- 1
- 2
- 3
- 4
创建一个Conda环境
这里举例,创建一个名为"pytorch"的环境,测试是否可以操作:
# 1 执行下面命令
conda create -n pytorch python=3.9
# 2 弹出确认,选择y
Proceed ([y]/n)?
# 3 跑完进度,弹出 working done,激活环境输入:
conda activate pytorch
# 4 shell左侧的括号内从base->pytorch后代表切换环境成功
# 5 使用命令查看有哪些包
pip list
CUDA网:https://pytorch.org/
选择CUDA,首先打开英伟达找到自己的显卡型号:https://www.nvidia.cn/geforce/technologies/cuda/supported-gpus/
或者使用CMD命令nvidia-smi
查看自己的CUDA
2022.11.20 在官网所选择的安装例:
Stable(1.13.0) + Windows + Conda + Python + CUDA 11.6
# 1 执行安装命令 conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia # 2 弹出安装列表,询问是否安装,选择y
- 1
- 2
- 3
小插曲:发现之前安装是cpu版本的pytorch,重新安装了一遍:
# ROCM 5.1.1 (Linux only) pip install torch==1.12.1+rocm5.1.1 torchvision==0.13.1+rocm5.1.1 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/rocm5.1.1 # CUDA 11.6 pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116 # CUDA 11.3 pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113 # CUDA 10.2 pip install torch==1.12.1+cu102 torchvision==0.13.1+cu102 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu102 # CPU only pip install torch==1.12.1+cpu torchvision==0.13.1+cpu torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cpu
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
然后等待安装… …安装完成后会提示All requested packages already installed
安装可能出现的报错
1.下载不动。参考上面配置清华源。
InvalidArchiveError("Error with archive G:\\Anaconda3\\pkgs\\nsight-compute-2022.3.0.22-0.tar.bz2. You probably need to delete and re-download or re-create this file. Message from libarchive was:\n\nfailed with error: [Errno 13] Permission denied: 'G:\\\\Anaconda3\\\\pkgs\\\\nsight-compute-2022.3.0.22-0\\\\nsight-compute\\\\2022.3.0\\\\target\\\\linux-desktop-glibc_2_11_3-x64\\\\ncu'")
- 1
这个报错,在我配置完清华源后只剩下一个包下载不下来了,来源英伟达官网的一个插件。不知道什么原因,于是按照他的文字提示我选择把这个目录的文件夹删除了。然后就可以了。
打开Python命令行,测试一下是否可以使用了(是否安装好了)
>>> import torch
>>> torch.cuda.is_available()
True
2.过几天又False了,不知道什么情况,然后重新安装一遍就好了。
>>> import torch >>> torch.__version__ '1.10.0+cu102' >>> torch.cuda.is_available() True >>> ok
- 1
- 2
- 3
- 4
- 5
- 6
在安装完CUDA后操作。下载cudnn后,打开cuda的文件夹替换,使用CMD命令-set cuda
可以查看位置。
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
添加四个环境变量到Path中:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。