1. 程式人生 > 其它 >pip安裝超時問題

pip安裝超時問題

預設情況下 pip 使用的是國外的映象,在下載的時候速度非常慢,本文介紹2中處理方法

一)

1、設定超時時間

pip --default-timeout=1000 install -U 模組名

例如
pip --default-timeout=1000 install -U matplotlib
來下載matplotlib,讓它的延遲檢測時間變長。

2、使用映象網址來代替

國內清華大學的源:https://pypi.tuna.tsinghua.edu.cn/simple

豆瓣:https://pypi.douban.com/simple

中國科學技術大學 : https://pypi.mirrors.ustc.edu.cn/simple

阿里雲:https://mirrors.aliyun.com/pypi/simple/

華為雲:https://mirrors.huaweicloud.com/repository/pypi/simple

例如

pip install matplotlib -ihttps://pypi.tuna.tsinghua.edu.cn/simple

 -i:指定映象地址

這種只對當前安裝對命令有用,如果需要全域性修改,則需要修改配置檔案。

Linux/Mac os 環境中,配置檔案位置在 ~/.pip/pip.conf(如果不存在建立該目錄和檔案):

開啟配置檔案~/.pip/pip.conf,修改如下(可根據需要設定映象源):

[global]
index
-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn

檢視 映象地址:

$ pip3 config list   
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

Windows下,你需要在當前對使用者目錄下(C:\Users\xx\pip,xx 表示當前使用對使用者,比如張三)建立一個 pip.ini在pip.ini檔案中輸入以下內容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

二)

升級pip版本

pip install --upgrade pip -i https://pypi.douban.com/simple