-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
SciPy recipe fails with current development branch of P4A #3116
Comments
Current recipe uses SciPy maintenance/1.11.3: python-for-android/pythonforandroid/recipes/scipy/__init__.py Lines 18 to 20 in 9b0eed1
which uses a deprecated Numpy type np.int_t: https://github.com/scipy/scipy/blob/1d3a067c2ccd0a6efddeb3194163aa9a3879d26e/scipy/ndimage/src/_ni_label.pyx#L328-L331 for ni in range(num_neighbors):
neighbor_use_prev = (<np.int_t *> PyArray_ITER_DATA(itstruct))[0]
neighbor_use_adjacent = (<np.int_t *> (<char *> PyArray_ITER_DATA(itstruct) + ss))[0]
neighbor_use_next = (<np.int_t *> (<char *> PyArray_ITER_DATA(itstruct) + 2 * ss))[0] That was fixed in the SciPy version 1.12.0: for ni in range(num_neighbors):
neighbor_use_prev = (<np.npy_bool *> PyArray_ITER_DATA(itstruct))[0]
neighbor_use_adjacent = (<np.npy_bool *> (<char *> PyArray_ITER_DATA(itstruct) + ss))[0]
neighbor_use_next = (<np.npy_bool *> (<char *> PyArray_ITER_DATA(itstruct) + 2 * ss))[0] But the 1.12.0 release doesn't have the file /tools/cythonize.py So I tried again with an old version of SciPy, I saw the PR scipy/scipy#19320 about fixing the Cython version in 1.11.3 and releasing a final 1.11.4 version before the 1.12.0 release, using that version in the recipe also gave the original error. |
Is there anything that I can do to fix this recipe? The same error is produced with current development branch. |
I took a stab at it last summer and it was highly painful, hopefully things got better with recent releases, I don't know. from pythonforandroid.recipe import MesonRecipe
class ScipyRecipe(MesonRecipe):
... Then the workflow I'm using to rebuild is: # clean the build between rebuilds (not sure it's currently the best approach
p4a clean_recipe_build scipy && p4a clean_dists
# build using the testapps
cd testapps/on_device_unit_tests/
python setup.py apk \
--sdk-dir $ANDROID_SDK_HOME \
--ndk-dir $ANDROID_NDK_HOME \
--arch=x86_64 \
--requirements python3,scipy In fact I often build from the repository docker image, this is the way I like the best, but you can also build from your host. # build the image (or use the already published one)
docker build --tag=kivy/python-for-android .
# Docker run (note the volume mount so you don't have to rebuild the image after updating the recipe):
docker run -it \
--volume $(pwd)/pythonforandroid:/home/user/app/pythonforandroid \
--env ANDROID_NDK_HOME_LEGACY=/home/user/.android/android-ndk-legacy \
--env ANDROID_SDK_HOME=/home/user/.android/android-sdk \
--env ANDROID_NDK_HOME=/home/user/.android/android-ndk \
--rm kivy/python-for-android bash
# then from within the container, same thing as above
. venv/bin/activate
cd testapps/on_device_unit_tests/
python setup.py apk --debug \
--sdk-dir $ANDROID_SDK_HOME \
--ndk-dir $ANDROID_NDK_HOME \
--requirements python3,scipy \
--arch=armeabi-v7a # or whatever arch you like Good luck! 🏃 |
Ok I went through all the pain, here you go: https://github.com/T-Dynamos/python-for-android/tree/scipy_update You need to set ndk version to Here is my test: Apk size was Test code: import numpy as np
from scipy.integrate import quad
def f(x):
return np.sin(x)
result, error = quad(f, 0, np.pi)
print(f"Result of the integral: {result}")
print(f"Estimated error: {error}") Will open PR soon when will get more time (needs cleaning). |
Oh thanks, that was quick! I just managed to build the configuration. |
Edit: NVM fixed in latest commit. |
I'm getting this error with your fix: [INFO]: Downloading sdl2
[INFO]: -> directory context /home/mrisco/kivy/test_scipy/.buildozer/android/platform/build-x86_64/packages/sdl2
[DEBUG]: -> running basename https://github.com/libsdl-org/SDL/releases/download/release-2.30.11/SDL2-2.30.11.tar.gz
[DEBUG]: SDL2-2.30.11.tar.gz
[DEBUG]: * Generated md5sum: bea190b480f6df249db29eb3bacfe41e
[DEBUG]: * Expected md5sum: a344eb827a03045c9b399e99af4af13d
...
ValueError: Generated md5sum does not match expected md5sum for sdl2 recipe By changing the line 11 of pythonforandroid/recipes/sdl2/init.py to md5sum = 'bea190b480f6df249db29eb3bacfe41e' fix that. But I got a new error: [INFO]: Prebuilding scipy for x86_64
[INFO]: scipy has no prebuild_x86_64, skipping
[INFO]: Applying patches for scipy[x86_64]
[INFO]: Applying patch meson.patch
[DEBUG]: -> running patch -t -d /home/mrisco/kivy/test_scipy/.buildozer/android/platform/build-x86_64/build/other_builds/scipy/x86_64__ndk_target_24/scipy -p1 -i /home/mrisco/python/python-for-android/pythonforandroid/recipes/scipy/meson.patch
[DEBUG]: (Stripping trailing CRs from patch; use --binary to disable.)
[DEBUG]: can't find file to patch at input line 5
[DEBUG]: Perhaps you used the wrong -p or --strip option?
[DEBUG]: The text leading up to this was:
[DEBUG]: --------------------------
[DEBUG]: |Binary files scipy.git/.git/index and scipy.git.patch/.git/index differ
[DEBUG]: |diff '--color=auto' -uNr scipy.git/.git/logs/refs/remotes/origin/main scipy.git.patch/.git/logs/refs/remotes/origin/main
[DEBUG]: |--- scipy.git/.git/logs/refs/remotes/origin/main 2025-03-27 02:55:14.521123150 +0530
[DEBUG]: |+++ scipy.git.patch/.git/logs/refs/remotes/origin/main 2025-03-27 11:24:34.225186085 +0530
[DEBUG]: --------------------------
[DEBUG]: No file to patch. Skipping patch. That can be fixed by removing the references to .git folder in the meson.patch file: diff '--color=auto' -uNr scipy.git/meson.options scipy.git.patch/meson.options
--- scipy.git/meson.options 2025-03-27 02:55:14.586853766 +0530
+++ scipy.git.patch/meson.options 2025-03-27 02:07:29.736674085 +0530
@@ -2,6 +2,8 @@
description: 'option for BLAS library switching')
option('lapack', type: 'string', value: 'openblas',
description: 'option for LAPACK library switching')
+option('openblas_incldir', type: 'string', value: '', description: 'OpenBLAS include directory')
+option('openblas_libdir', type: 'string', value: '', description: 'OpenBLAS library directory')
option('use-g77-abi', type: 'boolean', value: false,
description: 'If set to true, forces using g77 compatibility wrappers ' +
'for LAPACK functions. The default is to use gfortran ' +
diff '--color=auto' -uNr scipy.git/scipy/meson.build scipy.git.patch/scipy/meson.build
--- scipy.git/scipy/meson.build 2025-03-27 02:55:14.632428649 +0530
+++ scipy.git.patch/scipy/meson.build 2025-03-27 11:25:33.756445056 +0530
@@ -268,10 +268,18 @@
endif
endif
+openblas_inc = get_option('openblas_incldir')
+openblas_lib = get_option('openblas_libdir')
+
+openblas_dep = declare_dependency(
+ include_directories: include_directories(openblas_inc),
+ link_args: ['-L' + openblas_lib, '-lopenblas']
+)
+
# pkg-config uses a lower-case name while CMake uses a capitalized name, so try
# that too to make the fallback detection with CMake work
if blas_name == 'openblas'
- blas = dependency(['openblas', 'OpenBLAS'])
+ blas = openblas_dep
elif blas_name != 'scipy-openblas' # if so, we found it already
blas = dependency(blas_name)
endif
@@ -295,7 +303,7 @@
# use that - no need to run the full detection twice.
lapack = blas
elif lapack_name == 'openblas'
- lapack = dependency(['openblas', 'OpenBLAS'])
+ lapack = openblas_dep
else
lapack = dependency(lapack_name)
endif |
WSL2 on Windows 11
Ubuntu 22.04.5 LTS
Buildozer 1.5.1.dev0
$LEGACY_NDK: android-ndk-r21e with fortran addons
Relevant configuration lines for buildozer.spec:
Minimal Kivy test:
Issue:
buildozer -v android debug
finished with the error: 'int_t' is not a type identifierThe text was updated successfully, but these errors were encountered: