踩坑指南!pytorch1.2.0安装!又是猛男落泪的一天!

    科技2026-01-15  10

    一定要看到最后!!! git的一个源码在train的时候要求pytorch的版本降到1.3.0以下。第一次试了1.2.0,下载太慢了,加源后源中找不到1.2.0,太拉垮了,看网上好多人都在用1.0.1,于是就试了一下这个。

    添加源:

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --set show_channel_urls yes conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

    安装命令:

    conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.2

    装好后检查:

    python >>>import torch

    无报错则证明安装成功。但是我出现错误:

    from torch._C import * ImportError: DLL load failed: 找不到指定的程序。

    太鸡肋啊啊啊啊,这个就是版本不匹配的问题,但是是哪个不匹配我真的花了很大的时间。 可能的解决方法:

    更改python版本,pytorch1.0.1自带的python版本为3.6.2,直接conda install python就可安装到对应版本。 更改numpy版本,看到有网有说更改为: conda install numpy=1.17。

    检查:

    print(torch.__version__) 1.0.1

    但是我现在cuda貌似和pytorch版本不匹配,等我再研究一下。

    完成上面后,官网给的安装语句里面pytorch1.0.1对应cuda10.0,我又重新降cuda版本。 这一步我是直接在pycharm的setting中修改的。 用下面的语句检查:

    import torch print(torch.__version__) print(torch.cuda.is_available()) print(torch.version.cuda)

    结果为:

    1.0.1 False None

    一开始没有最后一句,一直以为是torch和cuda版本不匹配,疯狂调cuda版本后,还是不行,就用最后一句查了一下torch期望的cuda版本,结果我人傻了,明明装的是pytorch-gpu版本,你居然告诉我我的torch期望的cuda版本是None(即cpu版本)???? 我怀疑可能是镜像源的问题??? 解决:我又重新装了torch1.2.0.。。。这次装成功了。

    conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0

    再次检查结果:

    1.2.0 True 10.0

    我tm终终终于。。。落泪!撒花!完结!

    Processed: 0.015, SQL: 9