前言
python使用pip方法安裝第三方包時(shí),需要從?https://pypi.org/?資源庫(kù)中下載,由于這個(gè)地址是國(guó)外的,速度簡(jiǎn)直慢的令人發(fā)指,還經(jīng)常連不上,于是在網(wǎng)上收集了幾個(gè)國(guó)內(nèi)的 pypi源以及配置訪(fǎng)問(wèn)
pypi國(guó)內(nèi)源
# 豆瓣(douban)
https://pypi.douban.com/simple
# 阿里云(http協(xié)議 服務(wù)器沒(méi)網(wǎng)使用nginx正向代理時(shí)可配置此源)
http://mirrors.aliyun.com/pypi/simple
# 中國(guó)科技大學(xué)
https://pypi.mirrors.ustc.edu.cn/simple
# 清華大學(xué)
https://pypi.tuna.tsinghua.edu.cn/simple
配置
1. 臨時(shí)使用
# 此參數(shù)“--trusted-host”表示信任,
pip install -i https://pypi.douban.com/simple/ --trusted-host pypi.douban.com?
2. 永久使用
2.1 linux系統(tǒng)
創(chuàng)建 pip.conf 文件
如果提示目錄不存在,自行創(chuàng)建一個(gè)(如果目錄存在,可跳過(guò)此步),如下:
mkdir ~/.pip
cd ~/.pip
首先打開(kāi)文件,命令如下:
sudo vim ~/.pip/pip.conf
接著,寫(xiě)入以下內(nèi)容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
# trusted-host 此參數(shù)是為了避免麻煩,否則使用的時(shí)候可能會(huì)提示不受信任
trusted-host = https://pypi.tuna.tsinghua.edu.cn?
2.2 Window系統(tǒng)
新建 pip 配置文件夾,直接在user用戶(hù)目錄中創(chuàng)建一個(gè)名為 pip 的文件夾( 即%HOMEPATH%\pip)
創(chuàng)建 pip.conf 文件
接著,寫(xiě)入以下內(nèi)容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
# trusted-host 此參數(shù)是為了避免麻煩,否則使用的時(shí)候可能會(huì)提示不受信任
trusted-host = https://pypi.tuna.tsinghua.edu.cn?
測(cè)試
修改完成后,使用 ” pip install xxx “(xxx為你要下載的包名),即可默認(rèn)使用國(guó)內(nèi)源下載。