pytorch安装和环境配置(anaconda多次安装失败,清华镜像源一次成功安装经验)

经历了无数个Anaconda官网安装的漫长等待,依然失败失败失败。最后转移目标到清华镜像源安装pytorch,很顺利,那一刻,我热泪盈眶!恐怕忘记,在这里写下安装过程,和大家一起分享学习。
参考博客:
https://blog.csdn.net/WannaSeaU/article/details/88427010
https://blog.csdn.net/weixin_42681868/article/details/99483974
https://blog.csdn.net/qq_44285092/article/details/107518862



1、打开cmd,输入4条命令

#添加清华镜像至Anaconda

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

#添加Pytorch镜像:

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

#for legacy win-64
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

2、在官网选择pytorch安装版本

在这里插入图片描述
将刚刚复制的命令和上一步4条命令一起输入到cmd,如下图所示:在这里插入图片描述
等待一点一点的下载:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

好了,到这里,安装已经成功!下面我们对安装好的pytorch进行测试,并看它是否有CUDA。

3、测试

import torch
import numpy
import torchvision
print(torch.__version__ )                   查看pytorch版本
print(torch.cuda.is_available())            是否有CUDA
输出:
1.7.1
True

我在cmd上运行的结果是这样:输入python——import pytorch>…(看下图)
在这里插入图片描述

4、Jupyter Notebook配置

激活到conda的pytorch环境下
#安装ipykernel
conda install ipykernel
#写入环境
windows:python -m ipykernel install  --name pytorch --display-name "Pytorch for Deeplearning"  #第一个name是conda中的虚拟环境名,第二个name是在jypyter notebook中显示的环境名称
linux:python -m ipykernel install  --name pytorch --user --display-name "Pytorch for Deeplearning"  #linux由于软件都是在user的权限下所以加一个user,(不然会报错没有root权限)
jupyter kernelspec list
jupyter notebook

我在cmd上运行的结果是这样:…(看下图)
在这里插入图片描述
在这里插入图片描述
Jupyter Notebook配置结束!下面再在pycharm上感受一下效果,哈哈

5、 Pycharm环境配置

新建一个项目project
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

好了,一切结束!恭喜你!顺利顺利顺利!

6、总结

pycharm》help》about                             查看pycharm版本2020.3.3   (我电脑安装的各个版本)
python                                           查看python版本3.8.5
import torch;print(torch.__version__)           查看pytorch的版本1.7.1
nvcc -V                                          查看CUDA版本V10.2.89
print(torch.cuda.is_available())                 cuda是否可用



pip&conda源
pip下载镜像

清华镜像:https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣镜像:https://pypi.doubanio.com/simple
阿里镜像:https://mirrors.aliyun.com/pypi/simple/
中国科技大学:http://pypi.mirrors.ustc.edu.cn/simple/

conda

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

在这里插入图片描述

  • 10
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值