I am trying to se python in android studio as a backend code for working on variables and producing answer. My MainActivity is in Java and a directory is created for python code. when I try to write code in python is tells that "no python interpreter configured for the module" I have added Chaquopy and Python Community Plugin. Also I want to know how can I send variables for my MainActivity to python and viceversa.
I am trying to add python in android studio. I have tried Chaquopy and also Python Community Plugin. I have tried to find answers on different places and guides too. But no Luck till now.
buildscript {
repositories {
google()
jcenter()
maven{url "https://chaquo.com/maven"}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "com.chaquo.python:gradle:0.5.0"
}
}
this is MainActivity and I want to send my variable "a" to python file to work on it.
package com.example.testingpython;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int a=2;
String[] array={"My","Name","Java"};
}
}
QPython is a script engine that runs Python on android devices. It lets your android device run Python scripts and projects. It contains the Python interpreter, console, editor, and the SL4A Library for Android.
However, you can write Python script and include it in your project, then write in your application part that will invoke it somehow. Also, you can use Android Studio as a text editor for Python scripts. To develop apps for Android in Python you have to use a proper library for it.
Do one of the following: Click the Python Interpreter selector and choose Add New Interpreter. Press Ctrl+Alt+S to open the project Settings/Preferences and go to Project: <project name> | Python Interpreter. Click the Add Interpreter link next to the list of the available interpreters.
Navigate to File | Project Structure or press Ctrl+Alt+Shift+S . , and choose Add Python SDK from the popup menu. In the left-hand pane of the Add Python Interpreter dialog, select System Interpreter. and in the Select Python Interpreter dialog that opens, choose the desired Python executable and click OK.
These are steps that work:
when I try to write code in python is tells that "no python interpreter configured for the module"
Only a few features of the Python Community Edition plugin will work properly in Android Studio. You can still write your Python code in Android Studio if you want, but most of the IDE assistance will be unavailable.
Even if the code displays error indicators, you can still go ahead and run your app, and if any of the errors are real, the details will be displayed in the Logcat.
how can I send variables for my MainActivity to python and viceversa.
See the example code in the Chaquopy documentation and demo app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With