The easiest solution โ€“ Chaquopy

https://chaquo.com/chaquopy/

Works for me

Answer from Mikhail Sharin on Stack Overflow
๐ŸŒ
Medium
medium.com โ€บ globant โ€บ how-i-made-python-interoperate-with-kotlin-a11358e48da
How I Made Python Interoperate with Kotlin | by Shivhar Jalkote | Globant | Medium
September 22, 2022 - ... Both options donโ€™t fit the requirement so we decided to go with a Python script instead of a Python project. Python script will run on the same machine where the Kotlin server ...
Discussions

Need Help: Integrating Python with Kotlin Multiplatform
Setting aside for the moment the bigger question of why does this absolutely need to be married to python, can you not just offload this labor to a server where you can make the implementation as opinionated as you want in whatever language/ environment you want? If something is doing a bunch of labor and not just painting pixels on to the screen, it probably shouldn't need to live on multiple different platform implementations with caveats for each one. Let it live on a server. More on reddit.com
๐ŸŒ r/Kotlin
12
10
April 13, 2024
How to Execute a python code from an Android App (developed in Kotlin) - Android - Kotlin Discussions
I have a python script to do some task and I want to execute that script and send some arguments to it from my Android App which is developed in Kotlin. So my question is how to do it? ie. how can execute the python script and read its output in my Android App. Thanks in Advance. More on discuss.kotlinlang.org
๐ŸŒ discuss.kotlinlang.org
0
January 3, 2018
Run python script in intellij using kotlin - Stack Overflow
I have an assignment to do and i need to create a server in kotlin using intellij. I need to create a function that execute a python (TheHarvester lib in github) script but with out success. Note: ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
February 7, 2020
Running Python script from Java/Kotlin application on Heroku - Stack Overflow
I have a Java/Kotlin application that runs a Python script every time the user makes a request. It works well on my laptop and any other VPS. But I couldn't make it work on Heroku. It does not wor... More on stackoverflow.com
๐ŸŒ stackoverflow.com
September 16, 2018
๐ŸŒ
Medium
medium.com โ€บ @atifqamar29 โ€บ execute-python-script-from-android-app-kotlin-9f8d6a368566
Execute Python script from Android App (kotlin) - Atif Qamar - Medium
February 15, 2024 - Execute Python script from Android App (kotlin) The easiest way to use Python in an Android app โ€” Chaquopy Basic setup Add Chaquopy at the project and app/project build.gradle App-level โ€ฆ
๐ŸŒ
Reddit
reddit.com โ€บ r/kotlin โ€บ need help: integrating python with kotlin multiplatform
r/Kotlin on Reddit: Need Help: Integrating Python with Kotlin Multiplatform
April 13, 2024 -

Iโ€™m currently working on a Kotlin Multiplatform project and Iโ€™m exploring ways to integrate Python code into it. I came across Chaquopy (https://chaquo.com/chaquopy/), which is an SDK that allows Python code to run on Android. However, my project needs support across multiple platforms, not just Android.

does anyone have Any recommendations for tools or libraries that support this?

๐ŸŒ
Kotlin Discussions
discuss.kotlinlang.org โ€บ android
How to Execute a python code from an Android App (developed in Kotlin) - Android - Kotlin Discussions
January 3, 2018 - I have a python script to do some task and I want to execute that script and send some arguments to it from my Android App which is developed in Kotlin. So my question is how to do it? ie. how can execute the python scโ€ฆ
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 60101897 โ€บ run-python-script-in-intellij-using-kotlin
Run python script in intellij using kotlin - Stack Overflow
February 7, 2020 - I have an assignment to do and i need to create a server in kotlin using intellij. I need to create a function that execute a python (TheHarvester lib in github) script but with out success. Note: I have installed the python plugin. ... fun executeScript() : String { val process = Runtime.getRuntime().exec( "../resources/theHarvester/theHarvester.py" ) process.waitFor() val reader = BufferedReader(InputStreamReader(process.inputStream)) val message = reader.lines().collect(Collectors.joining("\n")) println(message) return "" }
๐ŸŒ
Readthedocs
kotlin-for-python.readthedocs.io โ€บ en โ€บ latest โ€บ hello_world
Hello World โ€” Kotlin for Python Developers 1.0.0 documentation
In Python we have the Python Console tool window, which opens the Python interpreter in the context of your project. The Kotlin REPL is the same idea. ... Here we typed a line of Kotlin code and executed it with Cmd-Enter (macOS.) We could have clicked the green play button, which triggers ...
Find elsewhere
๐ŸŒ
Dickens
dickens.co.in โ€บ python-embedded-in-kotlin
Call Python from Kotlin or embed Python code inside Kotlin | Learn With Dickens
November 22, 2019 - package plot import python.* import kotlinx.cinterop.* fun main(args: Array<String>) = memScoped { Py_SetProgramName(null) Py_Initialize() //Direct python script embedding PyRun_SimpleStringFlags( """ from time import time,ctime print('Today is',ctime(time())) """ ,null) //External python code located in PYTHONPATH //#load module multiply or multiply.py from PYTHONPATH var pName = PyUnicode_DecodeFSDefault("multiply") var pModule = PyImport_Import(pName) //#load python function named "multiply" from the code var pFunc = PyObject_GetAttrString(pModule, "multiply") var pArgs = PyTuple_New(2L) //#set 2 parameters for the python method PyTuple_SetItem(pArgs, 0L, PyLong_FromLong(3)) PyTuple_SetItem(pArgs, 1L, PyLong_FromLong(3)) //#call the python method and get the result value var pValue = PyObject_CallObject(pFunc, pArgs) println("Result of call: " + PyLong_AsLong(pValue)); Py_Finalize() }
๐ŸŒ
Reddit
reddit.com โ€บ r/kotlin โ€บ embed python inside kotlin or call python from kotlin
r/Kotlin on Reddit: Embed Python inside Kotlin or call Python from Kotlin
November 23, 2019 - 71K subscribers in the Kotlin community. Discussion about Kotlin, a statically typed programming language for the JVM, Android, JavaScript, andโ€ฆ
๐ŸŒ
TopDealsNet
stlplaces.com โ€บ blog โ€บ how-to-run-a-python-function-in-kotlin
How to Run A Python Function In Kotlin in 2026?
September 20, 2025 - You can do this by adding the following ... the Jython library and make it available in your project. Create a Python script that uses the desired Python libraries....
๐ŸŒ
Medium
proandroiddev.com โ€บ chaquopy-using-python-in-android-apps-dd5177c9ab6b
Chaquopy: Using Python In Android Apps | by Shubham Panchal | ProAndroidDev
March 29, 2023 - Chaquopy is a framework that can help developers run Python scripts from Java/Kotlin code in Android apps. Unlike other cross-language libraries, there are no hassles of NDK or native code and the installation is easy.
๐ŸŒ
GitHub
gist.github.com โ€บ thomasnield โ€บ ceed8c3453b2bd22d352d9ba6397c8e7
Calling Kotlin from Python ยท GitHub
Clone this repository at &lt;script src=&quot;https://gist.github.com/thomasnield/ceed8c3453b2bd22d352d9ba6397c8e7.js&quot;&gt;&lt;/script&gt; Save thomasnield/ceed8c3453b2bd22d352d9ba6397c8e7 to your computer and use it in GitHub Desktop. Download ZIP ยท Calling Kotlin from Python ยท
Top answer
1 of 1
2

Heroku build apps based on buildpacks. Each buildpack knows how to build a certain kind of project, e.g. one might know how to install Maven dependencies and compile Kotlin source code, while another might know how to install Ruby gems.

In simple cases developers don't need to worry about this too much. When a buildpack isn't explicitly requested, Heroku tries to infer which buildpack it should use. Basically, it iterates through officially supported buildpacks in a given order and uses each buildpack's detection script to see if the project appears to match that buildpack.

Once it finds a matching buildpack it stops looking. In simple cases this is often sufficient. But each buildpack is designed to generate a fairly lean image; tools that you might expect to exist on a regular Linux box won't necessarily be present. In particular, the Java/Kotlin buildpack won't give you a python binary.

The good news is that with a bit of configuration you can use multiple buildpacks.

  1. First, set your main buildpack: heroku buildpacks:set heroku/java
  2. Then, add your secondary buildpack: heroku buildpacks:add --index 1 heroku/python
  3. Make sure your buildpacks are shown in the correct order (Python first, then Java), using heroku buildpacks

    The last buildpack in the list will be used to determine the process types for the application. Any process types defined from earlier buildpacks will be ignored.

  4. Finally, you may need to add an empty requirements.txt file to prevent the Python buildpack from failing to run. Alternatively, you could add any Python dependencies you may have.

    If you do have Python dependencies, consider using a Pipfile and Pipfile.lock instead of a requirements.txt. This will cause your app to be built using pipenv instead of pip.

๐ŸŒ
Kotlin Discussions
discuss.kotlinlang.org โ€บ native
Integrating a python code with kotlin - Native - Kotlin Discussions
April 16, 2022 - Hello, I recently wrote a python program and I wanted to integrate the program with my Kotlin application and anyone could tell me how can I do that ?
๐ŸŒ
Kotlin Discussions
discuss.kotlinlang.org โ€บ native
Kotlin interop with Python (via C) - Native - Kotlin Discussions
March 20, 2020 - I have some Kotlin code Iโ€™d like to re-use from a Python program/script. Is the best way to do this by using Kotlin Native to create a C library and then use that library from Python? Iโ€™ve looked at the Kotlin Native documentation on Github - and it looks like this should be possible. is ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 78072112 โ€บ how-to-run-python-code-using-android-kotlin-code
How to run python code using Android kotlin code - Stack Overflow
import com.chaquo.python.Python fun detectOCR(imagePath: String): String { val python = Python.getInstance() val module = python.getModule("ocr_utils") try { val results = module.callAttr("detectOCR", imagePath).toJava(JSONObject::class.java) return results.toString() } catch (e: Exception) { e.printStackTrace() return "error" } }
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ is it possible to use a python script in an android mobile application?
Is it possible to use a python script in an android mobile application? : r/learnpython
June 8, 2023 - You can use tools like "Termux" to run Python scripts on your Android device ... No. Not that way. OP wants his android app to execute python script and play result back in the app. ... Whatever library you are using, search for its kotlin/dart/java version and implement the same logic in android
๐ŸŒ
BetterCoding404
bettercoding404.github.io โ€บ blog โ€บ kotlin-python
Bridging the Gap: Kotlin and Python Integration | BetterCoding404
August 14, 2025 - Using a REST API: You can create ... the Python and Kotlin codebases separate. Using a subprocess: Kotlin can execute Python scripts as subprocesses and communicate with them through standard input and output....
๐ŸŒ
Frankel
blog.frankel.ch โ€บ kotlin-scripting-to-python
From Kotlin Scripting to Python
March 3, 2024 - The final problem in my setup was entirely unrelated to Kotlin scripting but was the push to change anyway. I had put the script inside the magic GitHub repo. For this reason, the GitHub history contained daily README commits sprinkled with dependency upgrades and my changes. I put the code in a different repo than the profile one. I now have two repositories: ... It fixes the latest issue I mentioned above. I chose Python because I used it for simple scheduled jobs in the last couple of years, and Iโ€™m happy enough about the results.