anaconda的所有的软件包全部在国外,安装起来很麻烦,关键是下载速度慢,而且经常中断,所以需要配置国内安装的镜像,下载速度就很快了。
2020/12/08更新:
最近发现·douban·源比较快
pip install pythonModuleName -i https://pypi.douban.com/simple
一、conda换国内源
1.1 查看源
命令
conda config --show-sources
显示结果
==> /home/xxx/.condarc <==
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
这里有两个源,一个是清华的源,另一个是默认的源
1.2 添加源(这里以添加清华源为例,当然也可以选择其他的源)
命令
conda config --add channels xxx
操作:
#添加清华的源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
运行成果后,使用显示源查看是否添加成功(conda config --show-sources)
1.3 其他可选的源(还有更多的可以网上搜索,这里不一一列举)
中科大的源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
阿里云的源
conda config --add channels http://mirrors.aliyun.com/pypi/simple/
1.4 移除源
命令
conda config --remove channels xxxx
移除全部
conda config --remove channels
例如,移除清华源
conda config --remove channels 'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/'
恢复默认源:
conda config --remove-key channels
设置显示源路径
conda config --set show_channel_urls yes
运行
conda clean -i
清除索引缓存,保证用的是镜像站提供的索引。
二、pip 源的修改:
永久修改:
Linux:
修改 pip.conf 文件 (没有就创建一个)
vi /home/xxx/.config/pip/pip.conf
修改内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple12
有时候经常出现的异常大概有几种:
1、pip 不是虚拟环境路径
那么使用 which python
得到python编译器路径: xxx/xxx/anaconda3/envs/nlp/bin/python
,然后:
xxx/xxx/anaconda3/envs/nlp/bin/python -m pip install xxxx
2、pip 源更新为国内后,却总是找不到
可能是上面永久修改[/home/.config/pip/pip.conf]
设置了 global url
将文本中的删除,然后就可以了
再不行,可以试试
pip install xxxx -i ttps://pypi.tuna.tsinghua.edu.cn/simple
3、pip更新
pip install --upgrade pip
python -m pip install --upgrade pip
附:清华大学开源软件镜像站
pypi 镜像使用帮助
pypi 镜像每 5 分钟同步一次。
临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
注意,simple 不能少, 是 https 而不是 http
设为默认
升级 pip 到最新的版本 (>=10.0.0) 后进行配置:
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U