默认 pip 是使用 Python 官方的源,但是由于国外官方源经常被墙,导致不可用,我们可以使用国内的 python 镜像源,从而解决 Python 安装不上库的烦恼。
- 网上有很多可用的源,例如:
- 豆瓣:http://pypi.douban.com/simple/
- 清华:https://pypi.tuna.tsinghua.edu.cn/simple
注意后面要有 / simple 目录!!!
1、临时使用,只有安装 pillow 时使用指定源
- pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pillow
2、永久修改,一劳永逸
- Linux下,修改 ~/.pip/pip.conf (没有就创建一个), 修改 index-url至tuna,内容如下:
- [global]
- index-url = https://pypi.tuna.tsinghua.edu.cn/simple
- windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下:
- [global]
- index-url = https://pypi.tuna.tsinghua.edu.cn/simple
来源: