패키지, 저장소 및 앱 카테고리 검색

chaquopy 표지
패키지 상세v0.0.20

chaquopy

Chaquopy 플러그인은 Chaquopy SDK를 사용하여 Flutter 앱에서 Python 스크립트를 실행합니다.

Android
30일 다운로드
218
좋아요
117
Pub 점수
160

패키지 설치

flutter pub add chaquopy

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Chaquopy는 Chaquopy SDK를 사용하여 Android 애플리케이션 내에서 Python 스크립트를 실행할 수 있게 해주는 Flutter 플러그인입니다. Dart에서 직접 Python 라이브러리 및 프레임워크에 접근할 수 있도록 Flutter 앱에 Python 코드를 원활하게 통합할 수 있습니다. 이는 모바일 앱에서 머신러닝 모델, 데이터 처리 작업 또는 기존의 Python 기반 로직을 활용하는 데 특히 유용합니다. 별도의 백엔드 서비스 없이 Android 디바이스에서 Python 코드의 설정과 실행을 간단히 할 수 있습니다.

사용 사례

  • Flutter 앱에서 머신러닝 모델 실행하기
  • 데이터 분석을 위한 파이썬 라이브러리 통합
  • 모바일 앱에서 레거시 파이썬 스크립트 실행하기
  • 복잡한 수학 계산 수행
  • 안드로이드 앱 내에서 파이썬 기반 API 사용

주요 기능

  • Flutter와의 네이티브 파이썬 통합
  • 인기 있는 Python 패키지 지원
  • Flutter pub를 통한 간편 설정
  • Android에서만 실행됨
  • 경량이고 효율적인 실행

적합한 대상

  • 파이썬 전문 기술을 가진 개발자
  • 고급 데이터 처리가 필요한 앱
  • 머신러닝 기반 모바일 애플리케이션
  • 기존 파이썬 코드베이스를 재사용하는 프로젝트
  • 안드로이드 중심의 플러터 개발자

고려 사항

  • Android 플랫폼에 한정
  • Python 런타임으로 인한 앱 크기 증가
  • 중량 계산에 대한 잠재적인 성능 오버헤드
  • Dart와 Python에 대한 이해가 필요합니다
  • iOS 배포에 적합하지 않습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Chaquopy Flutter plugin

This is an unofficial Chaquopy Flutter plugin to run Python code on Android. This is the simplest version, where you can write your code and run it.

Configuration Steps :

Add maven { url "https://chaquo.com/maven" } and add chaquopy dependency in dependencies section at project level gradle.build like following : You can find the latest-version of chaquopy here, also make sure to update the gradle, python and minimum SDK versions accordingly. You can find the compatible python, android gradle version and minimum SDK version based on chaquopy version here:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url "https://chaquo.com/maven" }
    }
    dependencies {
        ...
        classpath "com.chaquo.python:gradle:latest-version"
    }
}

Then, in the module-level build.gradle file (usually in the app directory), apply the Chaquopy plugin at the top of the file, but after the Android plugin:

apply plugin: 'com.android.application' 
apply plugin: 'com.chaquo.python' 

Apply ABI selection using following code.

defaultConfig {
    ndk {
       abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
    }
}

add this line to application tag in manifest file

android:name="com.chaquo.python.android.PyApplication".

After that sync your project.

Now, in your android folder, you'll have additional python folder created. Now, Download script.py and put it in python directory. (Kindly note that this python file should not be renamed other than script.py and also if your code doesn't work, check the intendations of the downloaded file.)

Now in order to use the chaquopy plugin import the chaquopy package in your flutter app through declaring the package inside pubspec.yaml file.

Now you can run the code easily by calling Chaquopy.executeCode(code) function which returns a map.

The map returned contains two properties and it contains follwing structure:

{
    "textOutputOrError" : "code output or error",
}

you can easily access this code via result["textOutputOrError"] , where result is variable of type map and you can name it anything you want.

FAQs:

  1. Why it shows the notification and also crashes the app after some time limit?

    This plugin uses Chaquopy SDK, which uses a license for the unlimited use case. In order to remove the notification and timelimit, you need to contact here for the license and after you get your license, you need to follow add follwing two lines in your local.properties file.

    1. chaquopy.license=your_license_key
    2. chaquopy.applicationId=package name of the app
  2. Can I use python packages?

    You can use all the python packages by using following configuration.

    defaultConfig {
        python {
            pip {
                install "scipy"
                install "numpy"
                //  specify any other package to install.
            }
        }
    }
    
  3. Why this package doesn't support OpenCV, Matplotlib and NLTK packages?

    I am writing reasons for individual packages here.

    1. OpenCV and Matplotlib : OpenCV and Matplotlib Requires a special configuration, I am working on this issue to be able to integrate in the package itself.

    2. NLTK and Spacy : NLTK and Spacy Packages can be installed and technically run on your device, but most of the NLTK and Spacy functionality relies on it's data that you will be downloading using nltk.download('all'). so It increases the size of the app significantly. I am also working on this feature.

  4. App Size Reduction:

    Using ABI Selection settings you can reduce the app size. The Python interpreter is a native component, so you must use the abiFilters setting to specify which ABIs you want the app to support. The currently available ABIs are:

    armeabi-v7a, supported by virtually all Android devices.

    arm64-v8a, supported by most recent Android devices.

    x86, for the Android emulator.

    x86_64, for the Android emulator.

During development you’ll probably want to enable them all, i.e.:

defaultConfig {
    ndk {
       abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
    }
}
  1. buildPython:

Some features require Python 3.5 or later to be available on the build machine. These features are indicated by a note in their documentation sections.

By default, Chaquopy will try to find Python on the PATH with the standard command for your operating system, first with a matching minor version, and then with a matching major version. For example, if Chaquopy’s own Python version is 3.8.x, then:

    On Linux and Mac it will try python3.8, then python3.

    On Windows, it will try py -3.8, then py -3.

If this doesn’t work for you, set your Python command using the buildPython setting. For example, on Windows you might use one of the following:

defaultConfig {
    python {
        buildPython "C:/path/to/python.exe"
        buildPython "C:/path/to/py.exe", "-3.8"
    }
}
  1. If you're facing Kotlin and Java compatibility issues, you can provide kotlin/java configuration as following:
android {
    compileSdk 34
    namespace 'com.chaquopy.chaquopy_example'

    kotlin {
        jvmToolchain(17)
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}
  1. You might need to update dsitributionUrl for the gradle based on the version you're using, which you can do inside gradle-wrapper.properties. you can find the available gradle urls here:
distributionUrl=URL
  1. Future Plans :

    [ ] Add support for opencv and matplotlib

    [ ] Add support for NLTK and Spacy

    [ ] Add support for apple devices as well. If you want to help me out with it, kindly contact me,through mail, and I will be happy make this plugin better.

Demo :

Queries :

All the configurations of chaquopy will work the same way, it's mentioned on the chaquopy sdk home page. if you don't find any solution you can open issue in the repository and I am happy to help. :)

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.