赞
踩
安装anaconda之后,想创建环境,用了下面这段代码:
conda create -n pytorch python=3.9
conda创建环境报错了,报了如下这一堆:
- 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 locations.
其实这个报错核心就是这句:
UnavailableInvalidChannel: The channel is not accessible or is invalid.
Channel无效,不能访问,Anaconda的Channel指的是Anaconda软件仓库的抽象概念,每一个channel代表一个特定的软件资源库,每一个channel有一个独立的安装源,用户可以添加,删除,管理这些软件资源库。Anaconda的channel可以帮助用户快速找到所需要的Python和R的软件包,并且可以在不同的操作系统中进行软件包的安装和管理。有点类似于源的概念,一个channel对应了一堆下载堆的概念。
也就是说核心问题在于换源,就是从国外源换成国内源。
找到换源的资料
在anaconda prompt 里执行:
conda config --set show_channel_urls yes
WHY?
为什么运行这段代码,因为:TUNA 提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等)的镜像,各系统都可以通过修改用户目录下的 .condarc
文件。Windows 用户无法直接创建名为 .condarc
的文件,可先执行 上面这段代码。
生成.condarc
文件如上图所示,在用户目录下建立.condarc文件,添加清华源:
- channels:
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- ssl_verify: true
其他源也一样,加上去即可。
附上:
- channels:
- - defaults
- show_channel_urls: true
- channel_alias: https://mirrors.bfsu.edu.cn/anaconda
- default_channels:
- - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
- - https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
- - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
- - https://mirrors.bfsu.edu.cn/anaconda/pkgs/pro
- - https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
- custom_channels:
- conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
- msys2: https://mirrors.bfsu.edu.cn/anaconda/cloud
- bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
- menpo: https://mirrors.bfsu.edu.cn/anaconda/cloud
- pytorch: https://mirrors.bfsu.edu.cn/anaconda/cloud
上海交通大学开源软件镜像站
-
- channels:
- - defaults
- show_channel_urls: true
- channel_alias: https://anaconda.mirrors.sjtug.sjtu.edu.cn/
- default_channels:
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/main
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/free
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/mro
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/msys2
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/pro
- - https://anaconda.mirrors.sjtug.sjtu.edu.cn/pkgs/r
- custom_channels:
- conda-forge: https://anaconda.mirrors.sjtug.sjtu.edu.cn/conda-forge
- soumith: https://anaconda.mirrors.sjtug.sjtu.edu.cn/cloud/soumith
- bioconda: https://anaconda.mirrors.sjtug.sjtu.edu.cn/cloud/bioconda
- menpo: https://anaconda.mirrors.sjtug.sjtu.edu.cn/cloud/menpo
- viscid-hub: https://anaconda.mirrors.sjtug.sjtu.edu.cn/cloud/viscid-hub
- channels:
- - defaults
- show_channel_urls: true
- default_channels:
- - http://mirrors.aliyun.com/anaconda/pkgs/main
- - http://mirrors.aliyun.com/anaconda/pkgs/r
- - http://mirrors.aliyun.com/anaconda/pkgs/msys2
- custom_channels:
- conda-forge: http://mirrors.aliyun.com/anaconda/cloud
- msys2: http://mirrors.aliyun.com/anaconda/cloud
- bioconda: http://mirrors.aliyun.com/anaconda/cloud
- menpo: http://mirrors.aliyun.com/anaconda/cloud
- pytorch: http://mirrors.aliyun.com/anaconda/cloud
- simpleitk: http://mirrors.aliyun.com/anaconda/cloud
清华大学开源软件镜像站
- channels:
- - defaults
- show_channel_urls: true
- channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
- default_channels:
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
- custom_channels:
- conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
修改保存后,即可添加 Anaconda Python 免费仓库。
运行下面这段代码:
conda clean -i
清除索引缓存,保证用的是镜像站提供的索引。
回到最开始的问题,这时就可以顺利创建环境了
conda create -n pytorch python=3.9
然后启用环境即可:
conda activate pytorch
左边的(pytorch)就是环境的名称了。
pip list查看有哪些包。
四、总结
看懂英文,对症下药
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。