pip安装python库通常用pip install x,x为python库名,默认使用的是国外的下载源,速度比较慢。
把pip安装源更换为国内镜像,可提升下载速度,还可提高安装成功率。
1.国内镜像:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
PS. 新版ubuntu要求使用https源。
2.使用方法:
在使用pip的时候加参数-i 和镜像地址,例如,使用清华镜像安装snownlp库:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple snownlp
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple snownlp
不想每次安装时都加上国内镜像地址,想将下载源永久修改为国内镜像地址,方法如下:
Linux系统:
修改 ~/.pip/pip.conf 中的内容为如下。
(没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
Windows系统:
在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容同如下。
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com