赶快收藏:快速安装PyTorch和TensorFlow(gpu+cpu+1.7.1+2.2.0--cuda_11.0.2_450.51.05)命令

如果有必要,记得先创建一个anaconda3虚拟环境:

onda create --name 环境名 python==3.7

cuda:

wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run
sudo sh cuda_11.0.2_450.51.05_linux.run

PyTorch

豆瓣源:

 pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.douban.com/simple some-package

或者1.7.0最新稳定版本:

pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.douban.com/simple some-package

https://pytorch.org/

或者
pip install torch=1.7.1 torchvision=0.8.2 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.douban.com/simple some-package
清华源:

pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

汇总:

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.douban.com/simple some-package

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

pip install torch==1.7.0+cu110 torchvision==0.8.1+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

TensorFlow

pip install --index-url https://pypi.douban.com/simple tensorflow

或指定版本:

install --index-url https://pypi.douban.com/simple tensorflow==1.15.0

在这里插入图片描述

TF-gpu2.X

pip install --index-url https://pypi.douban.com/simple tensorflow-gpu==2

在这里插入图片描述

win10+cuda10.2安装pytorch1.7.1(使用清华镜像源)

(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/

备注:
(1)torch和torchvison下载地址
https://download.pytorch.org/whl/torch_stable.html
在这里插入图片描述

(2)安装相应的pytorch版本

conda install pytorch torchvision cudatoolkit=10.2

(版本号从https://pytorch.org/上,查找对应版本)

参考文献:
https://blog.csdn.net/liubing8609/article/details/113359885

解决其他慢的参考文献:
https://www.zhihu.com/question/435340249

其他详细教程:
配置清华镜像源
我们使用Anaconda环境进行Pytorch的安装

在命令行中依次输入一下命令并执行

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

设置搜索时显示通道地址

conda config --set show_channel_urls yes

安装Pytorch
使用清华镜像源进行Pytorch的安装时,官方给出的安装命令就失效了

官方给出的安装命令是:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

如果使用清华镜像源安装Pytorch时,需要输入以下命令:

conda install pytorch torchvision cudatoolkit=10.1

在Linux上使用shell脚本一键安装
使用Linux系统的时候,有时一步一步复制粘贴命令非常麻烦,特别是使用远程服务器的时候。这时候就需要shell脚本一键解决复制粘贴命令的麻烦。

在任意文件目录下新建一个shell脚本文件,这里取名为 pytorch_install.sh

shell脚本文件的内容如下所示

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

设置搜索时显示通道地址

conda config --set show_channel_urls yes

安装pytorch

conda install pytorch torchvision cudatoolkit=10.1

在命令行中执行shell脚本,输入命令:

bash pytorch_install.sh
1
等待安装完成即可。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源代码杀手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值