Conda 创建虚拟环境报错解决方案:UnavailableInvalidChannel: The channel is not accessible or is invalid
使用conda创建虚拟环境时报错404
在命令行中运行命令:C:\Users\ykx>conda create -n test python=3.10
报错的具体信息为:
C:\Users\ykx>conda create -n test python=3.10
Collecting package metadata (current_repodata.json): failed
UnavailableInvalidChannel: The channel is not accessible or is invalid.
channel name: simple
channel url: https://pypi.tuna.tsinghua.edu.cn/simple
error code: 404
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 location
问题原因
遇到的错误是因为 误将 pip 的源配置成了 conda 的频道:
channel url: https://pypi.tuna.tsinghua.edu.cn/simple # ❌ 这是 pip 的源!
pypi.tuna.tsinghua.edu.cn/simple是 pip 使用的 PyPI 镜像- conda 需要使用 anaconda 频道,如
mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
两者格式不兼容,导致 404 错误。
解决步骤
第一步:查看当前配置
# 查看已配置的 channels
conda config --show channels# 查看配置文件位置及来源
conda config --show-sources
第二步:移除错误的 channel
# 方法1:按名称移除
conda config --remove channels simple# 方法2:按完整URL移除(更可靠)
conda config --remove channels https://pypi.tuna.tsinghua.edu.cn/simple
第三步:(可选)添加正确的清华 conda 源
# 添加主频道
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
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/# 显示 URL(便于调试)
conda config --set show_channel_urls yes
第四步:重试创建环境
conda create -n test python=3.10
第五步:(备选)如果如果有其它多余的channel也影响conda的频道 继续第二三步骤
如果还是上述报错,而且在查询channel时仍多出无用的频道,直接删除即可,下面是示例
# 查看已配置的 channels
conda config --show channels# 移除多余的channel
conda config --remove channels https://pypi.tuna.tsinghua.edu.cn
手动编辑配置文件(备选方案)(如上述操作不成功可采用本方案)
如果上述命令无效,可直接编辑配置文件:
- 找到配置文件位置(通常在):
- Windows:
C:\Users\user\.condarc - Linux/Mac:
~/.condarc
- Windows:
2.用文本编辑器打开,删除或注释掉错误行:
channels:
# - https://pypi.tuna.tsinghua.edu.cn/simple # ❌ 删除这行
- defaults
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ # ✅ 正确格式
3.保存后重试创建命令。
附:conda vs pip 源配置对照
conda conda config --add channels <url> https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
pip pip config set global.index-url <url> https://pypi.tuna.tsinghua.edu.cn/simple
⚠️ 切记:两个工具的源不能混用!
验证配置是否生效
conda config --show channels
conda info
如果配置正确,再执行 conda create -n label python=3.8 应该就能正常创建虚拟环境了。
更多推荐



所有评论(0)