pip换源和conda换源是不同的
在anaconda里面,可以使用pip install
的方法和conda install
的方法安装库,这二者的源是不同的,需要使用不同的代码来换源。
假设换了conda 的源,然后使用pip install
的方法进行安装,仍然使用的是默认的源。这一点一定要注意!
conda换源相关代码记录
添加删除镜像源
添加镜像源(以阿里云为例)
conda config --add channels http://mirrors.aliyun.com/anaconda/pkgs/main
conda config --add channels http://mirrors.aliyun.com/anaconda/pkgs/r
conda config --add channels http://mirrors.aliyun.com/anaconda/pkgs/msys2
conda config --add channels http://mirrors.aliyun.com/anaconda/pkgs/free
删除镜像源
conda config --remove channels http://mirrors.aliyun.com/anaconda/pkgs/msys2
删除所有镜像源(不包括default)
conda config --remove-key channels
其他设置
设置搜索时显示通道地址
conda config --set show_channel_urls yes
显示镜像源
显示当前所有的镜像源
conda config --show channels
显示镜像源和设置
conda config --show-sources
重要备注
conda换源时如果源无法使用,则也无法通过conda create语句创建新环境
2024.7.14实测conda的阿里云源无法使用
pip换源
添加源(以阿里云为例)
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com
注意,这里如果不添加第二句话,在pip install的时候,可能出现下面的报错
删除源
pip config unset global.index-url
查看当前有哪些源
pip config list
注:如果没有换源,只是默认源的话,输入pip config list
是空行,什么也不显示,如下图所示