一、镜像源来源
镜像的来源,一般指国内存放国外软件镜像的网站、服务器。为啥需要镜像源,在国内由于各种原因下载或更新国外的软件(比如python)网速特别慢甚至连不上。Ubuntu、Python、Nodejs、MySQL、Git、Chromium、Docker、Homebrew 等一系列的常用开源系统、软件都是国外开发的,下载地址位于国外,从国内访问、下载、更新。所以找个镜像网站就解决了。
二、镜像源常用代码
#显示镜像源
conda config --show-sources
#显示镜像源
conda config --show channels
#删除镜像源
conda config --remove-key channels #删除所有的镜像源,恢复到默认
conda config --remove channels [urls] #删除指定的镜像源
#添加新镜像
conda config --add channels http://pypi.douban.com/simple/
conda config --add channels http://mirrors.aliyun.com/pypi/simple/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
#国内常用源镜像地址:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:https://pypi.hustunique.com/
山东理工大学:https://pypi.sdutlinux.org/
豆瓣:https://pypi.douban.com/simple/
三、临时使用
pip
临时使用
可以在使用pip的时候加参数-i Simple Index
例如:pip install -i Simple Index numpy,这样就会从清华这边的镜像去安装numpy库。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy
永久修改
- Linux下,修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内容如下:pip
-
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
conda
conda是Anaconda中用来安装python包的工具。在Anaconda中将镜像分为两类,一类是官方的python包,放在anaconda中;另一类是第三方的python包,放在conda-forge中。
临时使用
采用conda 安装python包时,可以使用以下命令:
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64 joblib
在conda-forge中安装jieba第三方的Python包
conda install -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64 jieba
其中参数-c指定了镜像源的通道
永久修改
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes