conda channel镜像 conda使用清华源设置channel的镜像

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

conda channel镜像 conda使用清华源设置channel的镜像

宇内虹游   2021-05-16 我要评论
想了解conda使用清华源设置channel的镜像的相关内容吗,宇内虹游在本文为您仔细讲解conda channel镜像的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:conda,channel镜像,conda清华镜像,下面大家一起来学习吧。

前言

今天在下载OpenCV的时候发现清华的conda channel镜像已经不能用了,故在此记录:
1)如何显示所有channel;
2)如何更换channel。

1 显示所有channel

首先,conda config --show能够显示出所有conda的config信息。

如果我们只想看channels的信息,输入conda config --show channels即可,如下:

(base) C:\Users\dehen>conda config --show channels
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - defaults

现在我们有两个源,一个清华镜像,一个defauls默认下载源。

然而这个清华源已经不能用了,我在下载opencv的时候,输入:conda install opencv,但是报错:

(base) C:\Users\dehen>conda install opencv
Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64/repodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectionError(ReadTimeoutError("HTTPSConnectionPool(host='mirrors.tuna.tsinghua.edu.cn', port=443): Read timed out."))

所以我打算删除这个源。

2 移除清华镜像

输入:conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
这个命令是为了移除之前conda config --show channels显示的清华源。

(base) C:\Users\dehen>conda config --remove channels  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

(base) C:\Users\dehen>conda config --show channels
channels:
  - defaults

(base) C:\Users\dehen>

这时候再运行conda config --show channels会发现清华源已经被删除了

3 添加可用的清华源

参考[4],我发现自己之前安装的清华源的地址https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ 是清华维护的conda三方源之一conda-forge的镜像,,,此外清华还有很多可用的源。

所以我根据官网指示进行了添加:

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 --set show_channel_urls yes的意思是从channel中安装包时显示channel的url,这样就可以知道包的安装来源了。

4 下载opencv

在添加好这个源(channel)之后,我重新运行conda install opencv,果然能够成功下载!!!

但是中间竟然是自动安装,在安装前的确认[Y/N]的时候,conda直接跳过了,默认是Y。。。

这让我非常难受,所以我运行了:

conda config --set always_yes false

(这里的意思是安装确认中,不默认yes,而是由我来决定)

5 一些其他的conda指令

conda install <包名> 安装指定包
conda remove <包名> 移除指定包
conda update <包名> 更新指定包

参考文献

[1]Annaconda 增加删除镜像 channel, 以及其他python包安装解决办法

最开始是看到这里的评论,发现清华的源用不了。

[2] conda常用命令详解

在这里学到了一些conda的命令
[3] [加速]为conda添加国内镜像

在这里发现原来我之前添加的清华源,和真正的清华源不一样,这促使我进一步寻找可用的清华源。

[4] Anaconda 镜像使用帮助

这里是清华源的官网,我找到了可用的清华源并进行了安装。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们