pytorch安装文档
1.在conda中添加镜像源
C:\Users\tsl115 在你的用户下找到.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
2.在pycharm中由Conda管理的Python项目
这样conda环境就创建完成 了就可以在conda命令中用conda env list 查看现有的环境
工程创建完成后利用 conda activate Pytorch 进入对应环境中
(利用conda list 可以查看环境中可用软件包邮那些)
3.Pytorch安装
下载Pytorch
进入官网(百度即可)https://pytorch.org/
注:查看自己版本:nvidia-smi 确认自己的cuda版本
如果没有对应的cuda版本就选最近的,或者去历史版本中查找。所以我选的11.1.将选中部分复制到conda命令栏中进行安装
然后一路yes 即可
ok后打开pycharm 进行演示即可
# This is a sample Python script.
import torch
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
print(torch.__version__) ## pytorch版本
print(torch.version.cuda) ##cuda版本
print(torch.backends.cudnn.version()) # cudnn版本
print('gpu:',torch.cuda.is_available())# gpu加速是否可用
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help a https://www.jetbrains.com/help/pycharm/
显示以下内容则为安装成功
用pycharm安装软件包的方法
File -Setting-Project:(工程名:Pytorch)-PYthon interpreter[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GU0Ow76e-1646116941781)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301093750580.png)]