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

Android Studio使用Chaquopy下载chaquopy-libgfortran超时错误求助

Android集成Chaquopy时下载chaquopy-libgfortran==4.9超时问题

我在Android应用中通过Chaquopy集成Python功能,但下载chaquopy-libgfortran==4.9时出现读取超时错误,不确定是pip配置出错,还是有其他可实现需求的替代方案。

报错日志

Collecting chaquopy-libgfortran==4.9
  Downloading https://chaquo.com/pypi-13.1/chaquopy-libgfortran/chaquopy_libgfortran-4.9-0-py3-none-android_21_x86_64.whl (541 kB)
ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\urllib3\response.py", line 425, in _error_catcher
    yield
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\urllib3\response.py", line 507, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 454, in read
    n = self.readinto(b)
Exception:

  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 498, in readinto
    n = self.fp.readinto(b)
  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)
  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1241, in recv_into
    return self.read(nbytes, buffer)
  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1099, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
    status = self.run(options, args)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
    return func(self, options, args)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\commands\install.py", line 335, in run
    requirement_set = resolver.resolve(
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 179, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 362, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 314, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\operations\prepare.py", line 413, in prepare_linked_requirement
    local_file = unpack_url(
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\operations\prepare.py", line 197, in unpack_url
    file = get_http_url(
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\operations\prepare.py", line 126, in get_http_url
    from_path, content_type = _download_http_url(
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\operations\prepare.py", line 223, in _download_http_url
    for chunk in download.chunks:
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\cli\progress_bars.py", line 166, in iter
    for x in it:
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_internal\network\utils.py", line 15, in response_chunks
    for chunk in response.raw.stream(
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\urllib3\response.py", line 564, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\urllib3\response.py", line 529, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "C:\Users\Kezia\AppData\Local\Programs\Python\Python38\lib\contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\lib\site-packages\pip\_vendor\urllib3\response.py", line 430, in _error_catcher
    raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='chaquo.com', port=443): Read timed out.
Chaquopy: Exit status 2

> Task :app:generateDebugPythonRequirements FAILED
Execution failed for task ':app:generateDebugPythonRequirements'.
> Process 'command 'C:\Users\Kezia\Downloads\PersonalApp\app\build\python\env\debug\Scripts\python.exe'' finished with non-zero exit value 1 

项目build.gradle配置

python {
    version "3.8"
    buildPython "C:/Users/Kezia/AppData/Local/Programs/Python/Python38/python.exe"
    pip{
      install "numpy"
      install "opencv-python"
    }
}

解决方法

  • 排查网络稳定性:这类超时大多是网络连接不稳定导致的,试试切换网络(比如WiFi换手机热点)、重启路由器后重新构建项目。
  • 延长pip超时时间:在pip配置中添加超时参数,给下载更多缓冲时间:
    pip {
        install "numpy"
        install "opencv-python"
        options "--default-timeout=100"
    }
    
  • 手动下载依赖包:如果网络问题无法解决,手动下载报错中的whl包,放到项目app/src/main/python目录下,修改配置为本地安装:
    pip {
        install "./chaquopy_libgfortran-4.9-0-py3-none-android_21_x86_64.whl"
        install "numpy"
        install "opencv-python"
    }
    
  • 替代方案:如果Chaquopy依赖下载一直有问题,可以考虑其他Android集成Python的方式:
    • 使用Pyodroid:直接在Android上运行Python代码,适合简单场景;
    • 搭建Python服务端,Android通过网络请求调用接口;
    • 通过JNI调用编译好的Python C API,不过实现复杂度较高。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 05:22:14