PyPI鏡像使用指導
Python 包索引(The Python Package Index,PyPI)是 Python 編程語言的軟件存儲庫。官網(wǎng)站點:https://pypi.org/
但是國內由于各種各樣的原因,可能經(jīng)常會因為網(wǎng)絡問題而沒法按照預期來安裝我們期望的軟件包。這個時候就可以使用國內的PyPI鏡像來安裝了。
下面以清華大學開源軟件鏡像站的PyPI鏡像站為例來說明:
臨時使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package注意: simple 不能少, 是 https 而不是 http
設為默認
升級 pip 到最新的版本 (>=10.0.0) 后進行配置:
pip install pip -Upip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
如果您到 pip 默認源的網(wǎng)絡連接較差,臨時使用本鏡像站來升級 pip:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U使用如下方法也可以起到永久修改的目的。
?Linux環(huán)境 修改 ~/.pip/pip.conf (沒有就創(chuàng)建一個)
[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple?Windows環(huán)境 windows下,直接在user目錄中創(chuàng)建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini
[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple國內鏡像
?豆瓣:http://pypi.douban.com/simple?阿里云:http://mirrors.aliyun.com/pypi/simple/?中科大:http://pypi.mirrors.ustc.edu.cn/simple/?清華大學:https://pypi.tuna.tsinghua.edu.cn/simple?網(wǎng)易:https://mirrors.163.com/pypi/simple/
可能出現(xiàn)的問題處理
報錯內容
pip install mysql-pythonCollecting mysql-pythonThe repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host pypi.douban.com'.Could not find a version that satisfies the requirement mysql-python (from versions: )No matching distribution found for mysql-python
解決辦法
編輯 vim .pip/pip.conf
[install]trusted-host = pypi.tuna.tsinghua.edu.cn
原文:https://www.jeremysong.cn/cn/pypi-mirrors/
歡迎關注我的公眾號“須彌零一”,更多技術文章第一時間推送。
