The error Running cythonize failed can be a outcome when the numpy version you are building is not suitable for the python interpreter you are packaging. This can happen when you use Python for android and Buildozer.
Table of Contents
Error output
Following is the error output
Error compiling Cython file:
------------------------------------------------------------
...
self.rng_state.ctr.v[i] = counter[i]
self._reset_state_variables()
self._bitgen.state = <void *>&self.rng_state
self._bitgen.next_uint64 = &philox_uint64
^
------------------------------------------------------------
_philox.pyx:190:35: Cannot assign type 'uint64_t (*)(void *) except? -1 nogil' to 'uint64_t (*)(void *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
Traceback (most recent call last):
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/tools/cythonize.py", line 234, in <module>
main()
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/tools/cythonize.py", line 230, in main
find_process_files(root_dir)
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/tools/cythonize.py", line 221, in find_process_files
process(root_dir, fromfile, tofile, function, hash_db)
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/tools/cythonize.py", line 187, in process
processor_function(fromfile, tofile)
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/tools/cythonize.py", line 76, in process_pyx
subprocess.check_call(
File "/home/gk/.local/share/python-for-android/build/other_builds/hostpython3/desktop/hostpython3/Lib/subprocess.py", line 413, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/gk/.local/share/python-for-android/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3', '-m', 'cython', '-3', '--fast-fail', '-o', '_philox.c', '_philox.pyx']' returned non-zero exit status 1.
Traceback (most recent call last):
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/setup.py", line 461, in <module>
setup_package()
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/setup.py", line 443, in setup_package
generate_cython()
File "/home/gk/.local/share/python-for-android/build/other_builds/numpy/arm64-v8a__ndk_target_24/numpy/setup.py", line 248, in generate_cython
raise RuntimeError("Running cythonize failed!")
RuntimeError: Running cythonize failed!
Solution for Running cythonize failed!
If you observe, the error starts from numpy/tools/cythonize.py command in line number 15. The p4a build command is given below.
p4a apk --private $dir --package org.techris.omr --name "Techris OMR" --version 24.05.10 --bootstrap sdl2 --requirements python3==3.11.2,kivy,kivymd,numpy,opencv==4.9.0 --sdk-dir /home/gk/Android/Sdk --ndk-dir /home/gk/Documents/android-ndk-r25b-linux/android-ndk-r25b --android-api 34 --ndk-api 24 --arch armeabi-v7a --arch arm64-v8a --arch x86_64 --permission INTERNET --icon /home/gk/Documents/logo.png --presplash /home/gk/Documents/logo.png --presplash-color "#70AB44"
Here numpy is mentioned without any version number. To resolve the error you can change the version number
p4a apk --private $dir --package org.techris.omr --name "Techris OMR" --version 24.05.10 --bootstrap sdl2 --requirements python3==3.11.2,kivy,kivymd,numpy==1.22.3,opencv==4.9.0 --sdk-dir /home/gk/Android/Sdk --ndk-dir /home/gk/Documents/android-ndk-r25b-linux/android-ndk-r25b --android-api 34 --ndk-api 24 --arch armeabi-v7a --arch arm64-v8a --arch x86_64 --permission INTERNET --icon /home/gk/Documents/logo.png --presplash /home/gk/Documents/logo.png --presplash-color "#70AB44"
Sometimes, your python for android installation might be corrupted. It is better to try uninstalling and reinstall python for android to solve this issue