Python基礎(chǔ)之pip如何更換鏡像源
引言
在使用 pip安裝 Python包的時候會默認(rèn)從官方的 PyPI 源下載文件,但由于速度比較慢(官方下載源在國外)。國內(nèi)的一些公司和機構(gòu)提供了 PyPI 鏡像源(mirror source),可以通過設(shè)置來從國內(nèi)的鏡像源安裝 Python 包,以便提高下載速度。
常用國內(nèi)源
| 鏡像 | 網(wǎng)址 |
|---|---|
| 清華 | https://pypi.tuna.tsinghua.edu.cn/simple/ |
| 中科大 | https://pypi.mirrors.ustc.edu.cn/simple/ |
| 豆瓣 | http://pypi.douban.com/simple/ |
| 阿里 | https://mirrors.aliyun.com/pypi/ |
| 上交大 | https://mirror.sjtu.edu.cn/pypi/web/simple/ |
如何更改源
臨時更改
- 臨時修改源,命令如下
pip install <安裝包> -i <鏡像源>
- 示例如下:
pip install beautifulsoup4 -i https://mirrors.aliyun.com/pypi/simple
- 如果上面的命令報下面的錯誤:
Collecting beautifulsoup4 The repository located at mirrors.aliyun.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 mirrors.aliyun.com'. Could not find a version that satisfies the requirement beautifulsoup4 (from versions: ) No matching distribution found for beautifulsoup4
則需要增加–trusted-host參數(shù):
pip install beautifulsoup4 -i https://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
永久更改
方法一、通過命令行配置
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip config set trusted-host pypi.tuna.tsinghua.edu.cn
- 如果部分模塊在國內(nèi)源上更新不及時,可以隨時切換回官網(wǎng),也即執(zhí)行下面的兩條命令之一:
pip config set global.index-url https://pypi.org/simple pip install xx -i https://pypi.org/simple
方法二、通過修改配置文件
Linux系統(tǒng)
- 如果沒有pip.conf文件,則先創(chuàng)建 ~/.pip/pip.conf文件:
mkdir ~/.pip && touch ~/.pip/pip.conf
- 修改pip.conf文件:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ [install] trusted-host = pypi.tuna.tsinghua.edu.cn
Windows系統(tǒng)
- 在Users目錄,新建一個pip目錄:
C:\Users\qxhgd\pip
- 在上述目錄中,新建一個pip.ini文件;
- 編輯pip.ini文件如下:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ [install] trusted-host = pypi.tuna.tsinghua.edu.cn
查看配置的源及配置文件路徑
- 通過下面命令,可以查看pip的相關(guān)配置:
pip config list
- 通過下面命令,可查看pip使用的配置文件的路徑:
pip config -v list
總結(jié)
到此這篇關(guān)于Python基礎(chǔ)之pip如何更換鏡像源的文章就介紹到這了,更多相關(guān)pip更換鏡像源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python企業(yè)編碼生成系統(tǒng)總體系統(tǒng)設(shè)計概述
這篇文章主要介紹了Python企業(yè)編碼生成系統(tǒng)總體系統(tǒng)設(shè)計,簡單描述了Python企業(yè)編碼生成系統(tǒng)的功能、結(jié)構(gòu)與相關(guān)編碼實現(xiàn)技巧,需要的朋友可以參考下2019-07-07
python 遺傳算法求函數(shù)極值的實現(xiàn)代碼
今天小編就為大家分享一篇python 遺傳算法求函數(shù)極值的實現(xiàn)代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
VSCode配置python環(huán)境及中文問題解決方法
這篇文章主要介紹了VSCode配置python環(huán)境及中文問題,print打印中文亂碼如何解決這個問題呢,本文給大家?guī)韮煞N方法幫助大家解決這個問題,需要的朋友可以參考下2022-02-02

