Python使用pip方法安装第三方包时,需要从 https://pypi.org/ 资源库中下载,但是会面临下载速度慢,甚至无法下载的情况,最好配置为国内源来进行python pkg包的安装和更新。
推荐几个国内镜像源 :
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
一:临时使用国内pypi镜像
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple ipython
二:永久使用国内pypi镜像
1、 Linux平台安装方式:
(1)创建pip.conf文件
首先运行以下命令
cd ~/.pip # 运行此命令切换目录
如果提示目录不存在,需要创建一个,如下:
mkdir ~/.pip cd ~/.pip
在 .pip目录下创建一个 pip.conf 文件,如下:
touch pip.conf
(2)编辑 pip.conf 文件
打开文件:
vi ~/.pip/pip.conf
写入以下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任
保存退出即可。
2、Window平台安装方式:
(1)新建 pip 配置文件夹,直接在user用户目录中创建一个名为 pip 的文件夹( 即%HOMEPATH%\pip);
(2)接着在 pip 文件夹中创建一个名为 pip 的文本文件(后缀名由” .txt “改为 ” .ini “),文本内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
修改完成后保存,在cmd中,使用 ” pip install xxx “即可默认使用国内源下载包。