解决:[anaconda安装pytorch]Collecting package metadata (current_repodata.json): failedYou will need to ad

解决Pytorch安装中的CondaHTTPError及依赖问题
本文记录了在安装Pytorch过程中遇到的Collecting package metadata失败问题,以及尝试的错误解决方案,如复制DLL文件、更新conda等。最终通过删除默认镜像源,添加清华源并重新安装解决了问题。同时提到了未安装CUDA却选择了CUDA版本的Pytorch导致的新问题,指出应选择无CUDA版本进行安装。

解决:Collecting package metadata (current_repodata.json): failed

  • 1.问题导入
  • 2.安装anaconda
  • 3.安装pytorch
  • 4.问题解决方式

1.问题导入

昨天运行一段代码,需要导包,但没有安装,按照pycharm中代码提示install package torch总出错:

m = torch.nn.MaxPool2d(3, stride=2)
input = autograd.Variable(torch.randn(20, 16, 50))
print(input.shape)
output = m(input)
output.shape

torch.Size([20, 16, 50])
torch.Size([20, 7, 24])

问了一下室友,室友刚学深度学习时有安装过这个,说用torch要安装pytorch,就给我发了个视频,装pytorch之前还要装anaconda。

视频链接:https://live.youkuaiyun.com/v/121851

2.安装anaconda

在这里插入图片描述

装完anaconda后,在cmd中执行 conda list命令 和conda --version 命令后,能查看到版本,就说明已经安装好了anaconda。

  • 执行conda list命令 有很多 只截取了部分
    执行conda list命令 有很多 只截取了部分
  • 执行conda --version 命令
    在这里插入图片描述
  • anaconda安装完成

3.安装pytorch

打开Pytorch官网https://pytorch.org/
在这里插入图片描述

  • 安装成功
    用管理员身份运行cmd,粘贴conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch 这条命令,有的电脑到这里能成功运行,就像室友的电脑一样,没有出任何错,直接就安装成功了。
    在这里插入图片描述
  • 安装失败
    用管理员身份运行cmd,粘贴conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch 这条命令,有的电脑到这里能成功运行,就像室友的电脑一样,没有出任何错,直接就安装成功了。但是我的电脑就出错了,忘记截图了。
    类似如下错误信息:
    Collecting package metadata (current_repodata.json): failed。
    An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get
    You will need to adjust your conda configuration to proceed.
    Use conda config --show channels to view your configuration’s current state,and use conda config --show-sources to view config file locations.
    PackagesNotFoundError: The following packages are not available from current channels:

4.问题解决方式

尝试了很多解决方法都不对。终于有一种正确了一些。

  • 错误的尝试一:
    按照下面的方式来解决掉:把路径“Anaconda3/Library/bin ”下面的文件复制到路径“Anaconda3/DLLs”下:
    libcrypto-1_1-x64.dll
    libssl-1_1-x64.dll
    再次运行命令行:
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
    还是报错,没有用。
  • 错误的尝试二:
    还有要更新anaconda的,也解决不了我的错误。
    conda update conda
    conda update anaconda
    conda update anaconda-navigator //update最新版本的anaconda-navigator
  • 等等。。。
  • 正确的解决方法:
    先删除已经设定好滴默认镜像源,执行下面的命令后就恢复了原来的源
    conda config --remove-key channels
    重新添加清华源
    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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
    conda config --set show_channel_urls yes
    重新执行这条命令:
    conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
    在这里插入图片描述

5.遗留问题待解决

但是又出现了其他问题,该怎么解决呀?
在这里插入图片描述

6. 目录5遗留问题的解决办法

现在是凌晨了,今天一天应该说昨天一天,什么也没有干成,就弄这个问题了,刚才忽然发现我没装CUDA却在装pytorch时选了cuda版本,欲哭无泪啊~
解决办法我已经写在了下一篇博客(解决:CondaHTTPError: HTTP 000 CONNECTION FAILED for url )里,https://blog.youkuaiyun.com/ckc_csdn/article/details/110847776

在 Windows 系统的 Anaconda 环境下,`conda install pytorch torchvision torchaudio cpuonly -c pytorch` 环境求解失败,可尝试以下解决办法: #### 检查网络连接 不稳定的网络可能导致环境求解失败。确保网络连接正常,可尝试切换网络环境或重启路由器。 #### 更新 Conda 旧版本的 Conda 可能存在兼容性问题,使用以下命令更新 Conda: ```bash conda update conda ``` #### 清理 Conda 缓存 缓存文件可能损坏或过时,导致环境求解失败。使用以下命令清理缓存: ```bash conda clean --all ``` #### 更换镜像源 使用国内镜像源可以加快下载速度,提高安装成功率。可使用清华大学的镜像源,添加以下内容到 `~/.condarc` 文件: ```plaintext channels: - defaults show_channel_urls: true default_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud ``` 添加完成后,使用以下命令更新缓存: ```bash conda config --set show_channel_urls yes ``` #### 指定版本安装 有时,不指定版本会导致依赖冲突。可以到 PyTorch 官网(https://pytorch.org/get-started/previous-versions/)选择合适的版本进行安装。例如,安装 1.10.1 版本的 CPU 版 PyTorch: ```bash conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cpuonly -c pytorch ``` #### 创建新的虚拟环境 旧的虚拟环境可能存在配置问题,创建一个新的虚拟环境并重新安装: ```bash conda create -n new_env python=3.8 conda activate new_env conda install pytorch torchvision torchaudio cpuonly -c pytorch ```
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值