conda | 设置软件源

目录

 

添加channels,以腾讯云为例

移除源

打印当前的channels

系统中的配置文件


添加channels,以腾讯云为例

腾讯源

conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/free/

conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/main/

conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/conda-forge/

conda config --add channels https://mirrors.cloud.tencent.com/anaconda/cloud/pytorch/

conda config --add channels https://mirrors.cloud.tencent.com/anaconda/pkgs/pro/

清华源

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/conda-forge/

conda config --add channels https://mirrors.tuna

<think> 嗯,用户想了解conda设置的方法。结合提供的引用内容,我需要整理几种主流配置方式。 用户引用的资料提到四种配置维度:临时使用、永久配置、代理设置和私有搭建,其中永久配置又分命令修改和手动编辑.condarc文件。这些恰好覆盖了conda设置的核心场景。 注意到引用[1][2]特别强调.condarc文件的关键作用,这个文件就像conda的"控制中心"。引用[3]则提到环境变量和代理设置的优先级问题——这个细节很重要,很多用户会遇到代理冲突。不过用户当前只需基础配置,暂时不需要展开代理部分。 用户上次询问的是pip配置,这次转向conda,说明ta可能在配置Python开发环境。考虑到国内用户普遍需要换加速,应该优先介绍镜像站配置。引用[2]列出的清华、阿里等镜像很实用,需要包含具体URL。 关于操作步骤:临时方案适合一次性使用,永久方案更适合长期开发。引用[1]提到的envs_dirs参数其实属于环境管理范畴,和设置关系不大,但可以提一句目录统一管理的好处作为延伸知识。 最后想到两个易错点需要提醒:https协议要求(引用[2]特别指出)和清除索引缓存的必要性。用户如果遇到配置未生效的情况,多半是缓存问题。 </think> 以下是 Conda 设置软件源的详细方法,涵盖临时使用、永久配置及常见场景: --- ### **一、临时指定(单次生效)** 1. **安装包时指定** ```bash conda install 包名 -c 镜像地址 # 示例:使用清华安装 numpy conda install numpy -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ ``` 2. **创建环境时指定** ```bash conda create -n 环境名 python=3.8 -c https://mirrors.aliyun.com/anaconda/pkgs/main/ ``` --- ### **二、永久配置镜像** #### **方法1:通过命令配置** ```bash # 添加清华 (main仓库) conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ # 添加 conda-forge 社区 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ # 设置搜索时显示通道地址 conda config --set show_channel_urls yes ``` #### **方法2:手动修改 `~/.condarc` 文件** 1. 编辑用户目录下的 `.condarc` 文件(Linux/macOS:`~/.condarc`;Windows:`C:\Users\用户名\.condarc`) 2. 替换为以下内容: ```yaml channels: - https://mirrors.aliyun.com/anaconda/pkgs/main/ - https://mirrors.aliyun.com/anaconda/pkgs/free/ - https://mirrors.aliyun.com/anaconda/cloud/conda-forge/ - defaults show_channel_urls: true ``` > ⚠️ **注意**: > - 配置文件优先级:`channels` 列表**从上到下**依次搜索包 > - 恢复默认:删除 `.condarc` 文件或执行 `conda config --remove-key channels` --- ### **三、常用国内镜像地址** | 镜像站 | Main 仓库 | Conda-forge 仓库 | |----------|------------------------------------------|-------------------------------------------| | **清华** | `https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/` | `https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/` | | **阿里** | `https://mirrors.aliyun.com/anaconda/pkgs/main/` | `https://mirrors.aliyun.com/anaconda/cloud/conda-forge/` | | **中科大**| `https://mirrors.ustc.edu.cn/anaconda/pkgs/main/` | `https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/` | --- ### **四、高级配置** 1. **避免搜索远程**(仅用本地配置) 在 `.condarc` 中添加: ```yaml channel_priority: strict ``` 2. **代理设置** ```bash # 终端临时设置代理 conda config --set proxy_servers.http http://127.0.0.1:8080 conda config --set proxy_servers.https https://127.0.0.1:8080 ``` 或在 `.condarc` 中添加: ```yaml proxy_servers: http: http://user:pass@corp.com:8080 https: https://user:pass@corp.com:8080 ``` 3. **私有配置** 引用私有地址到 `channels` 列表即可: ```yaml channels: - http://内部服务器IP:8080/自定义路径 - defaults # 保留公共 ``` --- ### **五、验证配置** ```bash conda config --show-sources # 查看生效配置 conda clean -i # 清除索引缓存后重试安装 ``` > 📌 **提示**: > 1. 国内需使用 `https` 协议,部分要求[信任SSL证书](https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/) > 2. 包搜索优先级:私有 > 国内镜像 > defaults(官方)[^2][^4] ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值