linux Ubuntu20.04 cuda11.5安装pytorch

最近学习pytorch,需要安装环境,我的cuda环境如下:
在这里插入图片描述

可以看到我的cuda 环境是11.5,然后在pytorch官网:https://pytorch.org/get-started/locally/
在这里插入图片描述
看到这里没有11.5,只有11.3,后来没办法直接安装先(需要安装anaconda环境)

pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113

安装以后出现如下,表示安装成功:
在这里插入图片描述
接着试了一下,看看有没有安装成功:
在这里插入图片描述
发现没有成功?
后来一想,应该要在anaconda环境下的python才行,然后:

cd /home/caizc/anaconda3/

Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()

果然成功了。

接着pycharm进行设置:
File->setting
在这里插入图片描述
在上面选择刚才anaconda中的python即可,因为在其它地方也安装了pytorch,所以位置非常重要。

测试:

import torch

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.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    print(torch.__version__)
    print('torch cuda:',torch.cuda.is_available())

在这里插入图片描述
OK 成功了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值