安装pytorch的过程及所见问题

1、安装anaconda

点击前往anaconda官网:www.anaconda.com

提示:建议下载最新版本的anaconda,不然容易出现如下报错:CondaError: Cannot link a source that does not exist. C:\Anaconda3\Scripts\conda.exe,之后可能还要再重新下载anaconda。

2、修改到清华源

在c盘/用户下找个.condarc这个文件,将里面的内容修改到如下:

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

提示:这里所有的源里都是http而不是https,如果引入https会报错 

3、设置超时时间

使用如下代码设置超时时间,这一点很重要,就算换成国内的清华源下载有时依旧非常缓慢,设置长时间的超时时间能让下载pytorch时系统不会自动断开下载。

pip --default-timeout=1000 install requests

4、去pytorch官网查找下载指令

Pytorch官网:https://pytorch.org

 选择对应版本(cuda要提前自己下载,非常简单)的语句,用管理员权限打开cmd,输入命令开始下载。

5、测试是否成功

输入python。1、输入import torch,如果输入后没有任何提示,就是成功了。2、然后再输入torch.cuda.is_available(),返回的是True,就是成功了。

6、可能遇到的问题

1、failed with initial frozen solve. Retrying with flexible solve

解决:去http://anaconda.org这个网站搜索你想要的包,这里就是搜索pytorch进行下载。

2、ERROR conda.core.link:_execute(502): An error occurred while uninstalling package 'defaults::numpy-base-1.15.1-py37h8128ebf_0'.

PermissionError(13, '拒绝访问。')

这里就是未用管理员权限访问。

3、import torch时出现如下问题

一般出现此问题原因可能有两个,一个是numpy的版本和python的版本不适配(python3.9和numpy1.19.4不适配),另一个就是安装numpy时候使用pip安全,而不是conda install numpy

解决:卸载当前numpy,代码如下:

pip uninstall numpy==1.21.5

 再安装对应版本,如果你不是1.19.4就安装自己当前版本,如果是的就安装numpy1.19.3,代码如下:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn numpy==1.19.3

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值