• 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:userszxyanaconda3libsite-packagespip\_ven
    dorurllib3
    esponse.py", line 425, in _error_catcher
        yield
      File "d:userszxyanaconda3libsite-packagespip\_ven
    ...
    raise IncompleteRead(self._fp_bytes_read, self.length
    _remaining)
      File "d:userszxyanaconda3libcontextlib.py", line 1
    30, in __exit__
        self.gen.throw(type, value, traceback)
      File "d:userszxyanaconda3libsite-packagespip\_ven
    dorurllib3
    esponse.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:userszxyanaconda3libsite-packages (from pdfminer3k) (3.8.0)
      Requirement already satisfied, skipping upgrade: ply>=3.4 in d:userszxyanaconda3libsite-packages (from pdfminer3k) (3.11)
      Requirement already satisfied, skipping upgrade: py>=1.5.0 in d:userszxyanaconda3libsite-packages (from pytest>=2.0->pdfminer3k) (1.6.0)
      Requirement already satisfied, skipping upgrade: six>=1.10.0 in d:userszxyanaconda3libsite-packages (from pytest>=2.0->pdfminer3k) (1.11.0)
      ...
      168c5dbe243c6f
      Stored in directory: c:userszxyappdatalocalpipcachewheelsa018f91cc04fb57e65aac816dce1bf6d01d6769e103820967a31ba4
      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:UsersHPDesktopscikit_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%pippip.ini),至少Windows7下“%HOMEPATH%pippip.ini”这个目录是不起作用的。
      2、在这里添加镜像源

    常用镜像源
    清华:https://pypi.tuna.tsinghua.edu.cn/simple
    阿里云:http://mirrors.aliyun.com/pypi/simple/
    中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

    参考博客链接:
  • 相关阅读:
    Android TextView里显示两种颜色
    Android 命令管理项目
    ANT build.xml文件详解
    Android Camera进行拍照
    Android 4.2以上的手机USB调试设置
    Android MediaPlayer和SurfaceView播放视频
    Android VideoView播放视频
    Android MediaRecorder录制音频
    Android Handler消息传递机制
    Android SurfaceView
  • 原文地址:https://www.cnblogs.com/z-712/p/12359360.html
Copyright © 2020-2023  润新知