欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python基礎(chǔ)之pip如何更換鏡像源

 更新時(shí)間:2024年08月05日 11:26:57   作者:花神廟碼農(nóng)  
pip的源是指pip安裝包所依賴的索引地址,下面這篇文章主要給大家介紹了關(guān)于Python基礎(chǔ)之pip如何更換鏡像源的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下

引言

在使用 pip安裝 Python包的時(shí)候會(huì)默認(rèn)從官方的 PyPI 源下載文件,但由于速度比較慢(官方下載源在國外)。國內(nèi)的一些公司和機(jī)構(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/

如何更改源

臨時(shí)更改

  • 臨時(shí)修改源,命令如下
pip install <安裝包> -i <鏡像源>
  • 示例如下:
pip install beautifulsoup4 -i https://mirrors.aliyun.com/pypi/simple
  • 如果上面的命令報(bào)下面的錯(cuò)誤:
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)源上更新不及時(shí),可以隨時(shí)切換回官網(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目錄,新建一個(gè)pip目錄:
C:\Users\qxhgd\pip
  • 在上述目錄中,新建一個(gè)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)文章

最新評(píng)論