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 plt.imshow函數(shù)及其參數(shù)使用
plt.imshow()是Matplotlib庫中的一個函數(shù),主要用于顯示圖像或矩陣數(shù)據(jù),本文主要介紹了Python plt.imshow函數(shù)及其參數(shù)使用,具有一定的參考價值,感興趣的可以了解一下2024-02-02
python實現(xiàn)批量修改服務(wù)器密碼的方法
這篇文章主要介紹了python實現(xiàn)批量修改服務(wù)器密碼的方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-08-08
pytorch之torch.nn.Identity()的作用及解釋
這篇文章主要介紹了pytorch之torch.nn.Identity()的作用及解釋,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
Python輕松實現(xiàn)將Excel數(shù)據(jù)批量導(dǎo)入數(shù)據(jù)庫
在日常數(shù)據(jù)處理工作中,將 Excel 文件內(nèi)容導(dǎo)入數(shù)據(jù)庫是一個常見需求,本文將基于輕量級 Excel 處理庫完成 Excel 文件解析,結(jié)合 Python 內(nèi)置的 SQLite 數(shù)據(jù)庫,實現(xiàn)多工作表自動識別、動態(tài)創(chuàng)建表結(jié)構(gòu)、批量數(shù)據(jù)入庫的完整方案,希望對大家有所幫助2026-04-04

