python中pip install 命令出現異常時的解決方案


報錯信息:

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0581C150>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/numpy/

 

原因:請求超時,數據源有問題。

默認pip是使用Python官方的源,但是由於國外官方源經常被牆,導致不可用,我們可以使用國內的python鏡像源,從而解決Python安裝不上庫的煩惱。

 

解決辦法:

1、修改源(臨時):
可以在使用pip的時候在后面加上-i參數,指定pip源。

eg:    

  1.  
    pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
  2.  
     
  3.  
    pip install numpy -i http://pypi.douban.com/simple

如果有如下報錯:

請使用命令:

pip install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

 

其他一些國內的pip源,如下:

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

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

豆瓣(douban) http://pypi.douban.com/simple/

清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/

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

#### 注意后面要有/simple目錄!!! ####

 

2、修改源方法(永久修改):

linux:
修改 ~/.pip/pip.conf (沒有就創建一個), 內容如下:

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

windows:
直接在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,

windows在%HOMEPATH%\pip\pip.ini中寫入

內容如下:

  1. [global] 
  2. index-url = http://pypi.douban.com/simple
  3. [install] 
  4. trusted-host=pypi.douban.com

 
這樣在使用pip來安裝時,會默認調用該鏡像。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM