buildozer icon indicating copy to clipboard operation
buildozer copied to clipboard

Custom recipe for scipy with cythonrecipe

Open advent-embedded opened this issue 4 years ago • 1 comments

Ive a stripped down functionality of scipy lfilter, i could successfully build my recipe when targeted for host PC x86_64, which gives shared object built via cython when i include the same recipe to kivy, i could pass the compilation step, while installation it stilll seeks to install at my development machine instead of ardroid folders.

 RAN: /home/sosdt002/kivy/plotgraph/.buildozer/android/platform/build/build/other_builds/hostpython3/desktop/hostpython3/native-build/python setup.py install -O2

  STDOUT:
running install
running build
running build_ext
running install_lib
creating /usr/local/lib/python3.7
error: could not create '/usr/local/lib/python3.7': Permission denied

advent-embedded avatar Jul 22 '20 06:07 advent-embedded

my scipy recipe from local folder

from pythonforandroid.recipe import CythonRecipe
from pythonforandroid.toolchain import Recipe, shprint, current_directory,info
import urllib.parse
import sh
import glob

class ScitoolsRecipe(CythonRecipe):
    url = 'file://' + urllib.parse.quote("/home/sosdt002/Desktop/scitools")
    name = 'scitools'

    depends = ['numpy', 'cython']

    def build_arch(self, arch):
        Recipe.build_arch(self, arch)  # a hack to avoid calling
                                   # PythonRecipe.build_arch
        self.build_cython_components(arch)
        self.install_python_package(arch)  # this is the same as in a PythonRecipe

    def install_python_package(self,arch):
        '''Automate the installation of a Python package (or a cython
        package where the cython components are pre-built).'''
        # arch = self.filtered_archs[0]
        env = self.get_recipe_env(arch)
        # shprint(echo, '$PATH', _env=env)        
        info('Installing {} into site-packages'.format(self.name))

        with current_directory(self.get_build_dir(arch.arch)):
            hostpython = sh.Command(self.ctx.hostpython)

            # shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
    
    def build_cython_components(self, arch):
        env = self.get_recipe_env(arch)
        info("arch={}".format(env))
        with current_directory(self.get_build_dir(arch.arch)):
            hostpython = sh.Command(self.ctx.hostpython)

            # This first attempt *will* fail, because cython isn't
            # installed in the hostpython
            try:
                shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env)
            except sh.ErrorReturnCode_1:
                pass

            # ...so we manually run cython from the user's system
            shprint(sh.find, self.get_build_dir('armeabi-v7a'), '-iname', '*.pyx', '-exec',
                      'cython', '{}', ';', _env=env)

            # now cython has already been run so the build works
            shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env)

            # stripping debug symbols lowers the file size a lot
            build_lib = glob.glob('./build/lib*')
            shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
                    env['STRIP'], '{}', ';', _env=env)
            shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)

recipe = ScitoolsRecipe()

reading around blogs i found running buildozer with root is not advise to overcome permission issue

advent-embedded avatar Jul 22 '20 06:07 advent-embedded