Android运行scipy | 运行python
chaquopy之前收费现在免费,收到资助
which meets the following requirements:
环境需求:
Android Gradle plugin version should be between 4.1 and 7.2.
minSdkVersion must be at least 21
In your top-level build.gradle
file
// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '4.2.2' apply false id 'com.android.library' version '4.2.2' apply false id 'com.chaquo.python' version '14.0.2' apply false } task clean(type: Delete) { delete rootProject.buildDir }
In the module-level build.gradle
file
plugins { id 'com.android.application' id 'com.chaquo.python' } android { compileSdk 32 defaultConfig { applicationId "com.example.demo_chaquopy" minSdk 21 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" python { buildPython "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python39\\python.exe" pip { install "scipy" install "pandas" // install "opencv-python" install "matplotlib" } } ndk { abiFilters "armeabi-v7a", "arm64-v8a" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation files('libs\\hellocharts-library-1.5.8.jar') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
pip里面添加你要安装的库,不是所有的库都可以顺利安装,但是这是目前最好的方案了
这样就把库导入到你的项目了怎么用,构建一下,会自动下载你要的库,下不下来你就要那个你懂的操作
在这个目录添加你的py代码
def sayHello(): print("Hello World")
在java里调用
if (!Python.isStarted()){ Python.start(new AndroidPlatform(this)); } Python python=Python.getInstance(); PyObject pyObject=python.getModule("hello"); pyObject.callAttr("sayHello");
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了