【好用】一条命令解决pytouch安装的版本匹配问题
例如: CUDA 11.8 + Python 3.8。
·
- 安装的touch环境与CUDA和Python版本不匹配的问题。经过几次试验后发现,可以使用patch官网命令进行安装。直接自动匹配cuda和Python版本。比起使用requirement.txt安装要简单的多。
- 建议删除requirement中的touch,直接使用以下命令行。将最后的cu版本(我的是cuda11.8,就是cu118)改为自己本机安装的cuda版本。官网会自动匹配当前环境中的Python版本和win环境。
1 官方安装
直接通过 PyTorch 官网命令安装(自动匹配环境):
例如: CUDA 11.8 + Python 3.8
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
2 conda+镜像源
2.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/
# 以上两条是Anaconda官方库的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# 以上是Anaconda第三方库 Conda Forge的镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
#以上两条是Pytorch的Anaconda第三方镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch3d/
conda config --set show_channel_urls yes
conda info # 查看输入是否有效
2.2 安装
# 首先安装pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.8
# 使用官方网站提供的命令安装,参考:https://pytorch.org/get-started/previous-versions/
# 但是尤其注意以因为已经更换过conda源了,所以不需要添加-c pytorch -c conda-forge,否则默认从官方源添加
# 清华源的速度相较于原网站已经是快很多了(源网站知识2h+)。
# 此处仅指定cuda的版本是11.8,其他的版本适应匹配,避免出现安装中的不适配问题。
# 其次安装必要库
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
# 安装pytorch3d,只需要一条命令
conda install pytorch3d
参考文献
[1]https://blog.csdn.net/weixin_43357695/article/details/126063091
更多推荐


所有评论(0)