chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
838 stars 133 forks source link

Compilation on migration from Python version "3.8" -> "3.11" #939

Closed Gelassen closed 1 year ago

Gelassen commented 1 year ago

Chaquopy version

id("com.chaquo.python") version "14.0.2" apply false

Relevant parts of your build.gradle file

Module :chaquolib

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.chaquo.python'
}

android {
    namespace 'io.github.gelassen.chaquopylib'
    compileSdk 33

    defaultConfig {
        applicationId "io.github.gelassen.chaquopylib"
        minSdk 24
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
            // you may also import only some of them
        }
        python {    // this is not recognized in kts builds !!!
            version "3.11"
//            version "3.8"
            pip {
                install "matplotlib"
            }
            pyc {
                src false
            }
        }

    }

/*    sourcesJar {
        duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
    }*/

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
/*    implementation "androidx.core:core-ktx:1.9.0" */
    implementation "androidx.appcompat:appcompat:1.6.1"
    implementation "com.google.android.material:material:1.9.0"
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.7.20'
}

Describe your issue

I try to run my code with the most recent Python version. With Python version 3.8 I am able to compile code, with Python 3.11 I get this error:

Caused by: org.gradle.api.InvalidUserCodeException: Entry bootstrap.imy is a duplicate but no duplicate handling strategy has been set.

Duplicates during merge are know for me and in case of manifest it would look like this:

android {
    packagingOptions {
        pickFirst "META-INF/MANIFEST.MF"
        // exclude "META-INF/MANIFEST.MF"
    }
}

, but for this issue it is clear yet how it should be solved.

Sample code to reproduce the issue:

$ git clone https://github.com/Gelassen/chaquopy-integration.git
$ git checkout choir/python-version
Gelassen commented 1 year ago

I was able to run code with the latest python version with the latest but not-released-yet version of chaquopy.

However, I am getting TypeError: 'MainActivity$testPythonModule$Params1' object is not subscriptable, but it is seems to be just pure python related issue.

mhsmith commented 1 year ago

Sample code to reproduce the issue:

$ git clone https://github.com/Gelassen/chaquopy-integration.git
$ git checkout choir/python-version

Your project has a couple of structural problems:

Also, we don't currently have matplotlib for Python 3.11, only for 3.8, 3.9 and 3.10.

However, I am getting TypeError: 'MainActivity$testPythonModule$Params1' object is not subscriptable, but it is seems to be just pure python related issue.

If you need help with that, please create a separate issue with a full stack trace and the relevant sections of your code.

Gelassen commented 1 year ago

@mhsmith , thank you. Where can I look on all supported packages/modules?

Regarding issue, I have rolled back to use chaquopy directly, without wrapper. Similar calls gives different errors. Also call a simple sum_func from a class gives strange error, but a call to the same sum_func out of the class works fine. I will prepare an issue in next ten minutes.

Update: https://github.com/chaquo/chaquopy/issues/943

Gelassen commented 1 year ago

Also I am interested to know what should be done to have python package/module supported by chaquopy? At this moment I need support of transformers and ``ckip-transformers``` to run this classifiers. May be I could help with it.

https://pypi.org/project/transformers/ https://pypi.org/project/ckip-transformers/

At this moment I get an error:

Could not find a version that satisfies the requirement torch>=1.5.0 (from ckip-transformers) (from versions: none)

for ckip-transformers and:

Command errored out with exit status 1:
can't find Rust compiler
Failed building wheel for tokenizers
Command errored out with exit status 1:
can't find Rust compiler
Failed building wheel for safetensors
Could not build wheels for tokenizers, safetensors which use PEP 517 and cannot be installed directly
Process 'command 'python3.10'' finished with non-zero exit value 1 

for transformers

mhsmith commented 1 year ago

Where can I look on all supported packages/modules?

Our native-compiled packages are all listed here:

As well as these packages, Chaquopy also supports most pure-Python packages on PyPI.

At this moment I need support of transformers and ``ckip-transformers```

We don't support the current version of transformers, but you can try an older version as shown at https://github.com/chaquo/chaquopy/issues/608#issuecomment-1107441743.

Gelassen commented 1 year ago

Thank you, I even have found instructions on how to port new packages in case I or anyone would like to contribute https://github.com/chaquo/chaquopy/tree/master/server/pypi.

Gelassen commented 1 year ago

I am closing issue, because I was able to build and run the most recent version of chaquopy despite its alfa version.