Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom Python libraries: No module named 'numpy.core._multiarray_umath' #76

Closed
JayKyne opened this issue Mar 1, 2024 · 2 comments

Comments

@JayKyne
Copy link

JayKyne commented Mar 1, 2024

I'm trying to build the flet_example app for Android on a Ubuntu 23.10 system with a simple numpy import.

The p4a create --requirements numpy ... command for compiling the files works fine and the dart run serious_python:main package app/src --mobile also.

When building the apk with flutter build apk this results in an error:
/home/janik/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip: error: '/home/janik/Downloads/serious-python/src/serious_python/example/flet_example/build/serious_python_android/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libpythonbundle.so': The file was not recognized as a valid object file

Nevertheless I can install the apk to my Android device but I get a black screen.
Have you any ideas how to fix that?

@JayKyne
Copy link
Author

JayKyne commented Mar 7, 2024

The reason why I got a black screen was that I used Python 3.10 with p4a but Serious-Python expects Python 3.11 to run properly.
With the correct Python version the app starts but I get a new ImportError from NumPy which is shown in the app:

Traceback (most recent call last):
  File "/tmp/serious_python_tempGFODNN/__pypackages__/numpy/core/__init__.py", line 23, in <module>
  File "/tmp/serious_python_tempGFODNN/__pypackages__/numpy/core/multiarray.py", line 10, in <module>
  File "/tmp/serious_python_tempGFODNN/__pypackages__/numpy/core/overrides.py", line 6, in <module>
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 40, in <module>
  File "<frozen runpy>", line 229, in run_module
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/serious_python_tempGFODNN/main.py", line 4, in <module>
  File "/tmp/serious_python_tempGFODNN/__pypackages__/numpy/__init__.py", line 144, in <module>
  File "/tmp/serious_python_tempGFODNN/__pypackages__/numpy/core/__init__.py", line 49, in <module>
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.11 from ""
  * The NumPy version is: "1.22.3"

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'

My requirements file in the app/src directory says numpy==1.22.3 and I used p4a create --requirements numpy==1.22.3 ... to create the Python executables. I guess this is somehow related to #75 .

@JayKyne JayKyne changed the title Adding custom Python libraries: libpythonbundle.so error Adding custom Python libraries: No module named 'numpy.core._multiarray_umath' Mar 7, 2024
@JayKyne
Copy link
Author

JayKyne commented Mar 8, 2024

My problem was that I thought I need the numpy==1.22.3 line in the app/src/requirements.txt file. This line should be deleted as NumPy is already part of the app when using p4a create --requirements numpy ... and export SERIOUS_PYTHON_P4A_DIST=.... Now everything works fine.

@JayKyne JayKyne closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant