對於Python開發用戶來講,PIP安裝軟件包是家常便飯。但國外的源下載速度實在太慢,浪費時間。而且經常出現下載后安裝出錯問題。所以把PIP安裝源替換成國內鏡像,可以大幅提升下載速度,還可以提高安裝成功率。
國內源:
新版ubuntu要求使用https源,要注意。
清華:https://pypi.tuna.tsinghua.edu.cn/simple
阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
華中理工大學:http://pypi.hustunique.com/
山東理工大學:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
臨時使用:
可以在使用pip的時候加參數-i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改,一勞永逸:
Linux下,修改 ~/.pip/pip.conf (沒有就創建一個文件夾及文件。文件夾要加“.”,表示是隱藏文件夾)
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,這樣就會從清華這邊的鏡像去安裝pyspider庫。
內容如下:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host=mirrors.aliyun.com
windows下
找到你python的安裝目錄下的文件
注意虛擬環境的話還需要改虛擬環境里的index.py
例如我的
D:\soft\PY\Lib\site-packages\pip_internal\models
下面的index.py文件
里面將PYPI的值改為你所需要的源即可,例如改為清華的源。
PyPI = PackageIndex(
‘https://pypi.tuna.tsinghua.edu.cn/simple’, file_storage_domain=‘files.pythonhosted.org’
)
保存文件即可.
