Python?pip指定安裝源的方法詳解
事件起因
有時候pip在安裝依賴庫的時候,由于默認(rèn)是國外的源,通常下載慢有時還會報錯,如下圖。

解決辦法
通過-i指定下載源地址即可使用國內(nèi)源進(jìn)行下載(以下方法僅為臨時指定)
命令格式 python -m pip install 安裝包名稱 -i 指定源地址 python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple 或 pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple 或 pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
以下是我收集的幾個國內(nèi)常用的下載源
https://pypi.tuna.tsinghua.edu.cn/simple #清華大學(xué) http://mirrors.aliyun.com/pypi/simple/ #阿里云 http://pypi.mirrors.ustc.edu.cn/simple/ #中國科學(xué)技術(shù)大學(xué) http://mirrors.cloud.tencent.com/pypi/simple #騰訊
臨時修改pip鏡像源的方式安裝某個安裝包(單次有效)
pip install 依賴包名稱 -i 鏡像源網(wǎng)址
例如通過阿里源安裝numpy包:
pip install numpy -i http://mirrors.aliyun.com/pypi/simple/
永久性修改pip的默認(rèn)的鏡像源
pip config set global.index-url 鏡像源網(wǎng)址
例如將華科大鏡像源設(shè)置為pip的默認(rèn)的鏡像源
pip config set global.index-url http://pypi.hustunique.com/
總結(jié)
到此這篇關(guān)于Python pip指定安裝源的文章就介紹到這了,更多相關(guān)Python pip指定安裝源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python 調(diào)用VC++的動態(tài)鏈接庫(DLL)
Python下調(diào)用VC++的動態(tài)鏈接庫的腳本2008-09-09
Python使用PyNmap進(jìn)行網(wǎng)絡(luò)掃描的詳細(xì)步驟
使用 PyNmap 進(jìn)行網(wǎng)絡(luò)掃描是一個非常有效的方式,PyNmap 是 Nmap 工具的一個 Python 封裝,它允許你在 Python 腳本中使用 Nmap 的強(qiáng)大功能,本文介紹了如何使用 PyNmap 進(jìn)行網(wǎng)絡(luò)掃描的詳細(xì)步驟,需要的朋友可以參考下2024-08-08

