You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决Python中pip安装scipy的读取超时错误

解决pip安装scipy时的读取超时问题

报错信息:

正在收集scipy
  下载scipy-1.12.0-cp312-cp312-win_amd64.whl.metadata (60 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.4/60.4 kB 14.5 kB/s 预计剩余时间 0:00:00
已满足依赖:numpy<1.29.0,>=1.22.4(来自scipy),已安装在c:\users\hp\appdata\local\programs\python\python312\lib\site-packages (1.26.4)
正在下载scipy-1.12.0-cp312-cp312-win_amd64.whl (45.8 MB)
   ━━━━━━━━━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.7/45.8 MB 115.5 kB/s 预计剩余时间 0:04:21

错误:异常:
回溯(最近的调用最后):
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第438行,在_error_catcher中
    yield
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第561行,在read中
    data = self._fp_read(amt) if not fp_closed else b""
           ^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第527行,在_fp_read中
    return self._fp.read(amt) if amt is not None else self._fp.read()
           ^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py",第98行,在read中
    data: bytes = self.__fp.read(amt)
                  ^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\http\client.py",第479行,在read中
    s = self.fp.read(amt)
        ^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\socket.py",第707行,在readinto中
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\ssl.py",第1253行,在recv_into中
    return self.read(nbytes, buffer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\ssl.py",第1105行,在read中
    return self._sslobj.read(len, buffer)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: 读取操作超时

在处理上述异常期间,发生了另一个异常:

回溯(最近的调用最后):
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\cli\base_command.py",第180行,在exc_logging_wrapper中
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\cli\req_command.py",第245行,在wrapper中
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\commands\install.py",第377行,在run中
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py",第179行,在resolve中
    self.factory.preparer.prepare_linked_requirements_more(reqs)
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\operations\prepare.py",第552行,在prepare_linked_requirements_more中
    self._complete_partial_requirements(
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\operations\prepare.py",第467行,在_complete_partial_requirements中
    for link, (filepath, _) in batch_download:
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\network\download.py",第183行,在__call__中
    for chunk in chunks:
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\cli\progress_bars.py",第53行,在_rich_progress_bar中
    for chunk in iterable:
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_internal\network\utils.py",第63行,在response_chunks中
    for chunk in response.raw.stream(
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第622行,在stream中
    data = self.read(amt=amt, decode_content=decode_content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第560行,在read中
    with self._error_catcher():
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\contextlib.py",第158行,在__exit__中
    self.gen.throw(value)
  文件 "C:\Users\Hp\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip\_vendor\urllib3\response.py",第443行,在_error_catcher中
    raise ReadTimeoutError(self._pool, None, "读取超时。")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): 读取超时。

可行解决办法:

  • 增加超时时间:手动设置更长的超时阈值,避免网络波动导致中断:

    pip install scipy --default-timeout=100
    

    数值可根据网络情况调整,比如设为300(5分钟)。

  • 使用国内PyPI镜像源:替换默认源为国内镜像,提升下载速度:

    pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
    

    也可临时指定多个镜像源:

    pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple -i https://mirrors.aliyun.com/pypi/simple/
    
  • 手动下载安装包本地安装:

    1. 找到对应版本的scipy whl文件(如你所需的scipy-1.12.0-cp312-cp312-win_amd64.whl);
    2. 下载到本地后,进入文件所在目录执行:
      pip install scipy-1.12.0-cp312-cp312-win_amd64.whl
      
  • 升级pip版本:旧版pip可能存在网络兼容性问题,先升级再安装:

    python -m pip install --upgrade pip
    pip install scipy
    
  • 检查网络环境:确认当前网络稳定,可尝试切换网络(如手机热点),或关闭代理/防火墙后重试。


内容的提问来源于stack exchange,提问作者Asif Iqbal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 19:24:59