要点:
- 修改conda的源,用清华源,具体修改方法详见
主要是要创建一个.condarc文件,内容改为下面这样的国内源。
ssl_verify: true
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- defaults
show_channel_urls: true
- 创建conda虚拟环境
网上类似教程很多,搜索即可
具体命令可以为
conda create -n pytorch
- 安装pytorch
具体就是运行
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
很多同志运行上面命令会出错,这里解释一下”-c”参数的含义,-c指的是从anaconda官方源的pytorch下载。这个是国外的地址,速度很慢。所以需要进行第四步的修改
4. 修改命令
错误方法:conda install pytorch torchvision torchaudio pytorch-cuda=11.7
本方法直接取消-c参数,但是提示各个包版本不兼容
正确方法:
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 cudatoolkit=11.7
直接强制指定各个库版本即可。
其中pytorch、torchvision、torchaudio版本有关联关系。如果要安装其他版本也可以,只要关联关系对应就可以。
附:上面是GPU方式,如果是CPU,就比较简单了,输入命令
conda install pytorch torchvision torchaudio
可以自动匹配上版本。
Original: https://blog.csdn.net/cxin917/article/details/127825180
Author: 高兴就好2048
Title: anaconda使用虚拟环境安装pytorch1.13+cuda11.7版(2022.11月测试有效)
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/660761/
转载文章受原作者版权保护。转载请注明原作者出处!