Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Python interpretor in android studio

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"};

}

}

like image 204
f158087 Muhammad Zohaib Avatar asked Feb 13 '19 10:02

f158087 Muhammad Zohaib


People also ask

Is there a Python interpreter for Android?

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.

Can I integrate Python in Android Studio?

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.

How do I fix invalid Python interpreter in Pycharm?

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.

How do I add Python interpreter to IntelliJ?

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.


2 Answers

These are steps that work:

  1. Install the JetBrains Python Community Edition.
  2. Click Tools -> Sync Python Requirements...
  3. A notification popup appears saying you need to configure your interpreter. Click the link in that popup. That link takes you to the necessary dialog window (the one you also see in Jiya's answer.) (That the link in the notification bar takes you to a different one is probably a bug.)

config

like image 75
YouCii Avatar answered Oct 20 '22 02:10

YouCii


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.

like image 5
mhsmith Avatar answered Oct 20 '22 02:10

mhsmith