目录
1、Anaconda
安装Anaconda
Anaconda下载地址(清华源):Anaconda安装
anaconda常见命令
**·**创建虚拟环境
conda create -n 环境名 python=3.7
**·**查看已经创建的虚拟环境
conda env list

**·**切换/进入环境
activate 环境名
· 删除环境
conda remove -n 环境名 -all(退出该环境再进行操作)
**·**复制环境
conda create -n 新环境名 --clone 旧环境名
**·**查看包
conda list
**·**查看显卡状态及使用情况
nvidia-smi
常用的镜像源
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
2、确定GPU能装什么版本的CUDA
**·**打开任务管理器

打开anaconda的Anaconda Prompt输入命令
nvidia-smi
查看GPU能够支持的最高CUDA版本

3、安装CUDA
如果支持CUDA11.x,建议先安装CUDA11.3,下载链接CUDA11.3

输入下列命令查看CUDA是否安装成功
nvcc -V

4、Pytorch安装
CUDA与pytorch版本对应

pytorch安装步骤
GPU版本建议离线安装,下载地址:pytorch下载
GPU版本选择cu,后面cp37的意思是python3.7版本,使用离线安装不涉及网络问题。
离线下载的优势是不出错,相对于在线下载方式很有优势。

· 下载好对应的torch后将其放在文件夹内

· 接下来进入存放torch的目标文件夹

· 使用pip命令进行离线下载
输入torch后按Tab键自动补全,后面加上镜像源。提高下载速度
pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple/

· 验证torch是否安装成功
//第一步进入python
python
//第二步导包看是否成功
import torch

· 从上述报错可以看出是numpy的问题,利用pip命令更新numpy
--退出python
输入Z
--更新numpy
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

· 之后再次进入python,查看torch是否下载成功
-- 进入python
python
-- 验证torch包
import torch

这样说明torch包下载成功且可以正常导入
· 查看torch版本、查看GPU是否可以用
import torch
-- 查看torch版本
print(torch.__version__)
-- 看CPU能不能用,能用返回Ture
print(torch.cuda.is_available())

5、安装torchvision
· torch和torchvision版本对应关系

torchvision下载地址:torchvision下载
找到与CUDA、python、torch相对应的torchvision版本

利用pip离线下载torchvision,输入torchvision后按Tab键即可自动补全路径
pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple/

查看torchvision是否安装成功
conda list

6、安装jupyter
为了让jupyter使用pytorch,需要在虚拟环境中下载jupyter
conda install ipython
conda install jupyter
安装完成后输入
jupyter notebook
之后在网页上新建一个python文件,看输出是否正常

7、pycharm的配置






pycharm终端配置,使用Anaconda
可以参考博客:终端配置



更改红色框选的路径为下图cmd.exe后面的内容之后重启pycharm终端即可

之后测试是否配置成功
