Я использую имя пакета «iop-python» для своего приложения kivy. Его нет в pythonforandroid для компиляции, поэтому я написал для него рецепт. Но у меня возникли проблемы с написанием рецепта.
Ссылка на репозиторий git пакета iop-python:
https://github.com/BukiOffor/ Hydra-python-api/tree/main
Мне нужно скомпилировать этот пакет с помощью pythonforandroid
Мне нужно скомпилировать этот iop-python с помощью Pythonдля Android, так что будет запустить на Android
Код рецепта
import os
from pythonforandroid.recipe import PythonRecipe
from pythonforandroid.toolchain import shprint
import sh
from os.path import join
class HydraPythonApiRecipe(PythonRecipe):
version = 'main'
url = 'https://github.com/BukiOffor/hydra-pyth ... ain.tar.gz'
# Define dependencies for building the Python package
depends = ['python3', 'setuptools', 'wheel', 'rust']
# Define Python-specific dependencies
python_depends = ['maturin', 'tomli']
def build_arch(self, arch):
super().build_arch(arch)
# Ensure setuptools is installed
shprint(sh.pip3, 'install', 'setuptools')
# Set up Rust toolchain for the specific target architecture
rust_target = 'armv7-linux-androideabi' if 'armeabi' in arch.arch else arch.arch
shprint(sh.rustup, 'target', 'add', rust_target)
# Define the build directory based on architecture
build_dir = self.get_build_dir(arch.arch)
# Run maturin to build the Python wheel using Rust
# Ensure you're using the correct target for cross-compilation
env = self.get_recipe_env(arch) # Get the appropriate environment
shprint(sh.maturin, 'build', '--release', '--target', rust_target, '--out-dir', build_dir, _env=env)
# Install the resulting wheel
wheel_path = join(build_dir, f'hydra_python_api-{self.version}-py3-none-any.whl') # Update to match your wheel name pattern
shprint(sh.pip3, 'install', wheel_path)
def get_recipe_env(self, arch):
"""
Set up the build environment for the architecture, including Rust flags.
"""
env = super().get_recipe_env(arch)
# Set Rust-related environment variables for cross-compilation
rust_target = 'armv7-linux-androideabi' if 'armeabi' in arch.arch else arch.arch
env['CARGO_BUILD_TARGET'] = rust_target
env['RUSTFLAGS'] = '--sysroot={}'.format(self.ctx.ndk_sysroot(arch))
return env
def install_dependencies(self):
"""
Ensure all Python dependencies are installed from requirements.txt.
This should be called before building.
"""
shprint(sh.pip3, 'install', '-r', 'requirements.txt')
# Register the recipe
recipe = HydraPythonApiRecipe()
Подробнее здесь: https://stackoverflow.com/questions/792 ... on-android
Как я могу использовать пакет oop-python на Android? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Python OOP – создать класс или построить в main.py (Udemy 100 дней Python)?
Anonymous » » в форуме Python - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-