No module named 'numpy.core._multiarray_umath' in android studio with chaquopy

75 views Asked by At

I want to use galois, an extension library of numpy in android studio with chaquopy. Because galois doesnt support the numpy versions available in the chaquopy repository i installed the wheels myself and installed numpy from there. However when i run the app i get this error:

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)

I tried different python versions and different numpy versions, however there are only few numpy versions compatible with galois. This is my 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"

            }
        }
1

There are 1 answers

0
mhsmith On

Linux wheels do not work on Android. So if you need to use a package that requires a newer version of NumPy, your options are:

  • Use an older version of the package that's compatible with the available versions of NumPy; or
  • Use a newer version of Python, as Chaquopy may have a newer version of NumPy to go with it; or
  • Use the Chaquopy package build tool to build a newer version of NumPy yourself.