pip install
添加参数 -i 国内源地址
#For Python2,使用清华源
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
#For Python3,使用清华源
pip3 install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
常用国内源地址:
阿里云
http://mirrors.aliyun.com/pypi/simple/
中国科技大学
https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban)
http://pypi.douban.com/simple/
清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学
http://pypi.mirrors.ustc.edu.cn/simple/
使用非HTTPS加密源(如豆瓣源),如果在执行命令发生错误,在命令最后加上–trusted-host 参数:
pip install scrapy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
以上方法是临时修改。如果需要永久修改,需要修改相应配置文件。
Linux
修改 ~/.config/pip/pip.conf
文件 (没有就创建一个)或者/etc/pip.conf
或者~/.pip/pip.conf
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
Mac
修改~/Library/Application Support/pip/pip.conf
文件
如果没有上面的文件,那么创建~/.config/pip/pip.conf
修改内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Windows
修改%APPDATA%\pip\pip.ini
文件 (没有就创建一个)
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
为Pyenv设置pip国内源
为某个版本的python设置pip国内源
编辑~/.pyenv/versions/{version}/pip.conf
(请自行替换{version})
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
为某个虚拟环境python设置pip国内源
编辑code ~/.pyenv/versions/{version}/envs/{virtualenv name}/pip.conf
(请自行替换{version}和{virtualenv name})
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple