chaquo / chaquopy

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

Build failed. Trying to install openai #1099

Closed Fuguro closed 7 months ago

Fuguro commented 7 months ago

Trying to install openai in android studio but getting build failed build.gradle module level:

plugins {
    id 'com.android.application'
    id 'com.chaquo.python'
}

android {
    namespace 'com.example.aibook'
    compileSdk 34

    defaultConfig {
        applicationId "com.example.aibook"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        ndk {
            abiFilters "arm64-v8a", "x86_64", "x86"
        }
    }

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

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

chaquopy {
    defaultConfig {
        pyc {
            src = false
        }
        pip {
            // A requirement specifier, with or without a version number:
            install "numpy"
            install "openai"
        }
        buildPython "C:\\Users\\Vladlen\\AppData\\Local\\Programs\\Python\\Python310\\python.exe"
    }
    productFlavors {}
    sourceSets {
        getByName("main") {
            srcDir "src/main/python"
        }
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

Build output:

> Task :app:createDebugVariantModel UP-TO-DATE
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:extractDebugPythonBuildPackages UP-TO-DATE

> Task :app:generateDebugPythonRequirements
Chaquopy: Installing for arm64-v8a
Looking in indexes: https://pypi.org/simple, https://chaquo.com/pypi-13.1
Collecting numpy
  Using cached https://chaquo.com/pypi-13.1/numpy/numpy-1.19.5-0-cp38-cp38-android_21_arm64_v8a.whl (3.8 MB)
Collecting openai
  Using cached openai-1.12.0-py3-none-any.whl (226 kB)
Collecting chaquopy-libgfortran>=4.9
  Using cached https://chaquo.com/pypi-13.1/chaquopy-libgfortran/chaquopy_libgfortran-4.9-0-py3-none-android_21_arm64_v8a.whl (495 kB)
Collecting chaquopy-openblas>=0.2.20
  Using cached https://chaquo.com/pypi-13.1/chaquopy-openblas/chaquopy_openblas-0.2.20-5-py3-none-android_21_arm64_v8a.whl (4.3 MB)
Collecting sniffio
  Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting pydantic<3,>=1.9.0
  Using cached pydantic-2.6.2-py3-none-any.whl (394 kB)
Collecting anyio<5,>=3.5.0
  Using cached anyio-4.3.0-py3-none-any.whl (85 kB)
Collecting distro<2,>=1.7.0
  Using cached distro-1.9.0-py3-none-any.whl (20 kB)
Collecting tqdm>4
  Using cached tqdm-4.66.2-py3-none-any.whl (78 kB)
Collecting typing-extensions<5,>=4.7
  Using cached typing_extensions-4.9.0-py3-none-any.whl (32 kB)
Collecting httpx<1,>=0.23.0
  Using cached httpx-0.27.0-py3-none-any.whl (75 kB)
Collecting pydantic-core==2.16.3
  Using cached pydantic_core-2.16.3.tar.gz (368 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Vladlen\AndroidStudioProjects\AIBook\app\build\python\env\debug\Scripts\python.exe' 'C:\Users\Vladlen\AndroidStudioProjects\AIBook\app\build\python\env\debug\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\Vladlen\AppData\Local\Temp\tmpazhgo44b'
         cwd: C:\Users\Vladlen\AppData\Local\Temp\pip-install-oi9fwy_e\pydantic-core
    Complete output (6 lines):

    Cargo, the Rust package manager, is not installed or is not on PATH.
    This package requires Rust and Cargo to compile extensions. Install it through
    the system's package manager or via https://rustup.rs/

    Checking for Rust toolchain....
    ----------------------------------------
ERROR: Failed to install pydantic-core==2.16.3 from https://files.pythonhosted.org/packages/77/3f/65dbe5231946fe02b4e6ea92bc303d2462f45d299890fd5e8bfe4d1c3d66/pydantic_core-2.16.3.tar.gz#sha256=1cac689f80a3abab2d3c0048b29eea5751114054f032a941a32de4c852c59cad (from pydantic<3,>=1.9.0->openai).
For assistance, please raise an issue at https://github.com/chaquo/chaquopy/issues.
Chaquopy: Exit status 1
IsakTheHacker commented 7 months ago

Try to add this requirement in your pip configuration:

install "pydantic<2"
Fuguro commented 7 months ago

Tried this but still doesn't work

IsakTheHacker commented 7 months ago

What's the new error?

Fuguro commented 7 months ago

Error remained the same

Fuguro commented 7 months ago

I just rewrote requirements in my pip configuration and it worked! Thank you very much!