pytorch安装文档

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项目

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SQGml8Vi-1646116941776)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301093140476.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mm4t1EdR-1646116941777)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301092929262.png)]

这样conda环境就创建完成 了就可以在conda命令中用conda env list 查看现有的环境

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BkA1LOGx-1646116941777)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301093233796.png)]

工程创建完成后利用 conda activate Pytorch 进入对应环境中

(利用conda list 可以查看环境中可用软件包邮那些)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Zg0lARS0-1646116941778)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301093345855.png)]

3.Pytorch安装

下载Pytorch

进入官网(百度即可)https://pytorch.org/

注:查看自己版本:nvidia-smi 确认自己的cuda版本

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SGAfVcGN-1646116941781)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301094516302.png)]

如果没有对应的cuda版本就选最近的,或者去历史版本中查找。所以我选的11.1.将选中部分复制到conda命令栏中进行安装

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tJl3DLzY-1646116941779)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301100859703.png)]
在这里插入图片描述

然后一路yes 即可

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-berFQm6r-1646116941779)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301100920007.png)]

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/

在这里插入图片描述

显示以下内容则为安装成功

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-X99MOrgE-1646116941780)(pytorch%E5%AE%89%E8%A3%85%E6%96%87%E6%A1%A3.assets/image-20220301144137631.png)]

用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)]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值