简体   繁体   中英

How to run a python function in kotlin?

I am making an app in kotlin. But I know python a lot and made the logic in python. The kotlin is only used for the display. Is there a way to call a python function in kotlin?. A python script can call python scripts but can a Kotlin script call one?

I think there are two normal solutions.

  1. Using Polyglot API of GraalVM ( https://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/package-summary.html ).

  2. Creating a C interface implemented with Python ( https://www.linuxjournal.com/article/8497 ) and calling it with JNI ( https://docs.oracle.com/javase/8/docs/technotes/guides/jni/ ). However, this option needs you to manage your objects and memory very carefully (dispose all C pointers properly etc.)

The easiest solution – Chaquopy

https://chaquo.com/chaquopy/

Works for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM