App下載

conda怎么使用清華源?設(shè)置channel鏡像詳解

享受養(yǎng)生的年輕人 2021-08-09 14:16:08 瀏覽數(shù) (28942)
反饋

由于眾所周知的原因很多國外的網(wǎng)站國內(nèi)訪問是比較慢的,其中conda的主站也有這個問題。國內(nèi)最常見的conda鏡像站是清華的鏡像站,但有時候清華的鏡像站也會面臨不能用的情況。本篇文章就來介紹一下conda怎么使用清華源和conda設(shè)置channel鏡像如何操作吧。

前言

今天在下載OpenCV的時候發(fā)現(xiàn)清華的conda channel鏡像已經(jīng)不能用了,故在此記錄:
1)如何顯示所有channel;
2)如何更換channel。

1 顯示所有channel

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

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

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

現(xiàn)在我們有兩個源,一個清華鏡像,一個defauls默認下載源。

然而這個清華源已經(jīng)不能用了,我在下載opencv的時候,輸入:conda install opencv,但是報錯:

(base) C:Usersdehen>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:Usersdehen>conda config --remove channels  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

(base) C:Usersdehen>conda config --show channels
channels:
  - defaults

(base) C:Usersdehen>

這時候再運行conda config --show channels會發(fā)現(xiàn)清華源已經(jīng)被刪除了

3 添加可用的清華源

參考[4],我發(fā)現(xiàn)自己之前安裝的清華源的地址https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ 是清華維護的conda三方源之一conda-forge的鏡像,,,此外清華還有很多可用的源。

所以我根據(jù)官網(wǎng)指示進行了添加:

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,果然能夠成功下載!?。?/p>

但是中間竟然是自動安裝,在安裝前的確認[Y/N]的時候,conda直接跳過了,默認是Y。。。

這讓我非常難受,所以我運行了:

conda config --set always_yes false

(這里的意思是安裝確認中,不默認yes,而是由我來決定)

5 一些其他的conda指令

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

到此這篇conda怎么使用清華源和conda設(shè)置channel鏡像如何操作的內(nèi)容就介紹到這了,希望能給小伙伴一些幫助,也希望小伙伴們多多關(guān)注W3Cschool!


0 人點贊