python安裝第三方庫時的一些bug 鏡像源修改


前序

飄得太久的,今天終於下定決心開始繼續學習了,第一步:打開我的PyCharm,第二部:安裝庫 報錯 o(╥﹏╥)o我太難了

D:\PyCharm_Project>`pip install pdfminer3K`
WARNING: Retrying (Retry(total=4, connect=None, read=None
eoutError("HTTPSConnectionPool(host='pypi.org', port=443)
WARNING: Retrying (Retry(total=3, connect=None, read=None
eoutError("HTTPSConnectionPool(host='pypi.org', port=443)
Collecting pdfminer3K
  Downloading pdfminer3k-1.3.1.tar.gz (4.1 MB)
     |█▌                              | 184 kB 4.2 kB/s
ERROR: Exception:
Traceback (most recent call last):
  File "d:\users\zxy\anaconda3\lib\site-packages\pip\_ven
dor\urllib3\response.py", line 425, in _error_catcher
    yield
  File "d:\users\zxy\anaconda3\lib\site-packages\pip\_ven
...
raise IncompleteRead(self._fp_bytes_read, self.length
_remaining)
  File "d:\users\zxy\anaconda3\lib\contextlib.py", line 1
30, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\users\zxy\anaconda3\lib\site-packages\pip\_ven
dor\urllib3\response.py", line 430, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed
out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSCon
nectionPool(host='files.pythonhosted.org', port=443): Rea
d timed out.

嘗試一:百度了一種做法即延時處理

  • D:\PyCharm_Project>pip --default-timeout=100 install pdfminer3k
    Collecting pdfminer3k
    Downloading pdfminer3k-1.3.1.tar.gz (4.1 MB)
    |██████ | 803 kB 11 kB/s eta
    ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREME
    update the hashes. Otherwise, examine the package contents caref
    pdfminer3k from https://files.pythonhosted.org/packages/8c/8
    ac2/pdfminer3k-1.3.1.tar.gz#sha256=1670de8ddb9aaff8f28d61abc918e
    Expected sha256 1670de8ddb9aaff8f28d61abc918e6a85c469fd8
    Got 08be56ca2bb19e6ebb7a9b3385c1b56861130b9f
    **

嘗試二:

  • D:\PyCharm_Project>pip --upgrade install pdfminer3k
    Collecting pdfminer3k
    Downloading pdfminer3k-1.3.1.tar.gz (4.1 MB)
    | | 10 kB 1.9 kB/s et
    ...
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
    pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pytho

嘗試三:完結篇

  • D:\PyCharm_Project>pip --default-timeout=200 install --upgrade pdfminer3k
    Collecting pdfminer3k
    Downloading pdfminer3k-1.3.1.tar.gz (4.1 MB)
    |████████████████████████████████| 4.1 MB 22 kB/s
    Requirement already satisfied, skipping upgrade: pytest>=2.0 in d:\users\zxy\anaconda3\lib\site-packages (from pdfminer3k) (3.8.0)
    Requirement already satisfied, skipping upgrade: ply>=3.4 in d:\users\zxy\anaconda3\lib\site-packages (from pdfminer3k) (3.11)
    Requirement already satisfied, skipping upgrade: py>=1.5.0 in d:\users\zxy\anaconda3\lib\site-packages (from pytest>=2.0->pdfminer3k) (1.6.0)
    Requirement already satisfied, skipping upgrade: six>=1.10.0 in d:\users\zxy\anaconda3\lib\site-packages (from pytest>=2.0->pdfminer3k) (1.11.0)
    ...
    168c5dbe243c6f
    Stored in directory: c:\users\zxy\appdata\local\pip\cache\wheels\a0\01\8f\91cc04fb57e65aac816dce1bf6d01d6769e103820967a31ba4
    Successfully built pdfminer3k
    Installing collected packages: pdfminer3k
    Successfully installed pdfminer3k-1.3.1

總結

pip下載超時處理 raise ReadTimeoutError(self._pool, None, ‘Read timed out.’)

方案一:對於比較小的庫,可以延時處理

Python pip --default-timeout=100 install -U pip
Python pip --default-timeout=100 install 第三方庫名

方案二:更換安裝源

網上可以查找很多豆瓣源,如https://pypi.tuna.tsinghua.edu.cn/simple/

Python pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts
Python pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 庫名

出錯使用這種 :Python pip install --index-url https://pypi.tuna.tsinghua.edu.cn/simple/ lightgbm

方案三:下載離線包

python所有庫:(https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml),然后通過pip install 保存路徑/加上下載的文件名 進行安裝 ,如
Python pip install C:\Users\HP\Desktop\scikit_image-0.14.1-cp37-cp37m-win32.whl

終極篇

1、在你的“C:\Users\你的用戶名\”目錄下創建“pip”目錄,“pip”目錄下創建“pip.ini”文件(注意:以UTF-8 無BOM格式編碼);
“pip.ini”文件內容:
[global] timeout = 6000 index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] use-mirrors = true mirrors = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.douban.com

  • 注意:trusted-host 選項為了避免麻煩是必須的,否則使用的時候會提示不受信任,或者添加“--trusted-host=mirrors.aliyun.com”選項;
  • 注意:有網頁提示需要創建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),至少Windows7下“%HOMEPATH%\pip\pip.ini”這個目錄是不起作用的。
    2、在這里添加鏡像源

常用鏡像源
清華:https://pypi.tuna.tsinghua.edu.cn/simple
阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/

參考博客鏈接:


免責聲明!

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



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