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

Android Studio+Chaquopy使用galois时遇numpy核心模块导入错误求助

问题:在Chaquopy中使用galois库时出现numpy C扩展导入错误

我希望在Android Studio中通过Chaquopy使用numpy的扩展库galois。由于galois不兼容Chaquopy仓库中的numpy版本,我自行安装了对应的wheel包(包括numpy),但运行应用时出现如下ImportError:

com.chaquo.python.PyException: ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "/system/bin/app_process32"
  * The NumPy version is: "1.25.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3782)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8177)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: com.chaquo.python.PyException: ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "/system/bin/app_process32"
  * The NumPy version is: "1.25.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'

    at <python>.numpy.core.<module>(__init__.py:49)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.numpy.<module>(__init__.py:139)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.galois._domains._array.<module>(_array.py:11)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.galois._domains.<module>(__init__.py:4)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.galois.<module>(__init__.py:20)
    at <python>.java.chaquopy.import_override(import.pxi:60)
    at <python>.generator.<module>(generator.py:1)
    at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:241)
    at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:883)
    at <python>.java.android.importer.exec_module(./java/android/importer.py:545)
    at <python>.java.android.importer.exec_module(./java/android/importer.py:597)
    at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:688)
    at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:1006)
    at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:1027)
    at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1050)
    at <python>.importlib.import_module(__init__.py:126)

我的build.gradle配置如下:

python{
            version "3.10"

            pip{

                install "galois"
                install "./libs/llvmlite-0.41.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
                install "./libs/numba-0.58.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl"
                install "./libs/numpy-1.25.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"

            }
        }

解决方案
  • 匹配Wheel包的架构与Python版本:

    • 当前llvmlite的wheel包是cp311版本,但Python用的是3.10,版本不兼容,必须下载cp310对应的llvmlite包。
    • 你用的是x86_64架构的wheel包,Android设备多为arm架构(arm64-v8a/armeabi-v7a),需下载对应目标架构的numpy、llvmlite、numba包,比如manylinux_2_17_aarch64版本。
  • 调整依赖安装顺序:
    先安装numpy,再安装依赖它的llvmlite、numba,最后安装galois,确保依赖解析正确:

    python{
        version "3.10"
        pip{
            install "./libs/numpy-1.25.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
            install "./libs/llvmlite-0.41.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
            install "./libs/numba-0.58.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.whl"
            install "galois"
        }
    }
    
  • 清理缓存并重建项目:
    执行Android Studio的Build > Clean Project和Build > Rebuild Project,清除旧构建缓存,确保新wheel包被正确打包到APK中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 01:25:34