修改Anaconda包下载的国内镜像源

anaconda 安装完成后,国内的网络连接Anaconda的官方源,速度基本为0,大部分时间是连接不上的。国内清华大学有对应的镜像源,可以更改为对应的源,可以通过更换原解决

首先在终端(Terminal)运行下面的命令生成 anaconda的 .condarc配置文件:

conda config
使用下面命令查看 .condarc 中的源

conda config --show channels


windows下

1 添加清华源或阿里源

打开anaconda prompt  ,在命令行中直接使用以下命令:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main/
conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/free/


 

# 设置搜索时显示通道地址

conda config --set show_channel_urls yes

这几个命令操作其实就是修改了Anaconda用户目录下的.condarc配置文件

当然,也可以直接在客户端里的菜单中打开配置文件修改:

如果源不可用,则会报404错误,需要重新配置

添加镜像的几个注意事项

  1. 频道没必要重复添加。 比如你添加了清华镜像的bioconda频道之后,北外镜像的bioconda频道就没必要添加了,这俩的内容是一致的,没必要又去让conda搜索一遍。
  2. 顺序是重要的。 conda在没有指定频道的前提下是从~/.condarc文件里从上往下一个频道一个频道去找软件的。所以如果把常用的频道放在最上面有利于更快地找到所需要安装的软件
  3. 就我目前的使用体验来看,如果做生物信息学相关的话,只需要添加:
  • bioconda
  • conda-forge
  • main

这三个频道就足够了。剩下的一些不常用频道可以在安装软件的时候手动用-c指定。

现在可用的 conda 镜像站点

接下来就盘点一下国内现在提供anaconda镜像服务的站点吧。顺便把命令也给大家准备好了,直接复制粘贴就可以使用啦。

1. 阿里云

conda config --add channels https://mirrors.aliyun.com/anaconda/pkgs/main/
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.aliyun.com/anaconda/cloud/bioconda/

2. 北京外国语大学

conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/cloud/bioconda/

3. 清华大学

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/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

4. 北京大学

conda config --add channels conda config --add channels https://mirrors.pku.edu.cn/anaconda/pkgs/main/
conda config --add channels conda config --add channels https://mirrors.pku.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels conda config --add channels https://mirrors.pku.edu.cn/anaconda/cloud/bioconda/

5. 哈尔滨工业大学

conda config --add channels https://mirrors.hit.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.hit.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.hit.edu.cn/anaconda/cloud/bioconda/


Linux下

将以上配置文件写在 ~/.condarc 中 
vim ~/.condarc

若安装了 sublime  的也可在终端使用  :subl ~/.condarc

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true
也可以把 anaconda 仓(https://repo.continuum.io/)的添加进去:

这是在anaconda安装 tensorflow1.4.1 的时候遇到的问题,把这个 anaconda 仓添加进去问题就解决了

channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://repo.continuum.io/pkgs/main
  - defaults
show_channel_urls: true
若源不生效,试着把.condarc文件中的 - defaults那行去掉
 

### 设置清华大学的 Conda 镜像源 为了通过 Anaconda 的命令行工具 `conda` 使用清华大学的镜像源来加速下载,可以按照以下方法操作: 可以通过修改 `.condarc` 文件或者直接运行命令的方式完成配置。以下是具体的操作说明。 #### 方法一:使用命令行方式 可以直接在终端中执行如下命令以设置清华大学的 Conda 镜像源[^2]: ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --set show_channel_urls yes ``` 如果还需要添加其他特定通道(channels),比如 `main` 或者 `conda-forge`,也可以分别添加这些通道对应的 URL 地址到配置文件中。例如: ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ ``` #### 方法二:手动编辑 .condarc 文件 另一种方法是手动编辑用户的 `.condarc` 文件。该文件通常位于用户主目录下 (`~/.condarc`)。如果没有这个文件,则可以从头创建它。打开此文件并加入以下内容即可实现同样的效果[^3]: ```yaml channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ show_channel_urls: true ``` 上述两种方法都可以有效更改默认仓库地址至清华大学开软件镜像站上的 Anaconda位置,从而提高国内网络环境下管理器的工作效率。 另外需要注意的是,在某些情况下可能也需要调整 Python 库安装工具 Pip 所使用的索引服务器链接以便进一步优化依赖项获取速度。这可通过下面这条指令达成目标: ```bash pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple ``` 以上就是关于如何利用 Anaconda 命令行为您的开发环境设定更快捷有效的清华镜像资的方法介绍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值