Running hello.py from an Android process

I am trying to run a python script hello.py from an Android process.

Here are the steps I followed:

  • I have purchased python binaries and need related libraries.
  • I tested them and they work in a terminal emulator.
  • I added them to my resource folder and copied them to private storage and made them executable.

But still I get the following error:

 07-19 13:35:15.391 26991-26991/com.vibhinna.example I/System.out: Here is the standard output of the command: 07-19 13:35:32.001 26991-26991/com.vibhinna.example I/System.out: Here is the standard error of the command (if any): 07-19 13:35:32.001 26991-26991/com.vibhinna.example I/System.out: Fatal Python error: Py_Initialize: Unable to get the locale encoding 07-19 13:35:32.001 26991-26991/com.vibhinna.example I/System.out: ImportError: No module named 'encodings' 07-19 13:35:32.001 26991-26991/com.vibhinna.example I/System.out: Current thread 0xb6f0dec8 (most recent call first): 

Here is the code used to execute the file.

  String pyPath = getFilesDir().getAbsolutePath() + "/usr/bin/python"; String helloPath = getFilesDir().getAbsolutePath() + "/usr/bin/hello.py"; ProcessBuilder pb = new ProcessBuilder(pyPath, helloPath); Process proc = pb.start(); BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); String s = null; while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } 

What am I doing wrong? How can I make this work?

+5
source share
1 answer

It was pure idiocy. After several days of hair pulling, I finally found out what went wrong. I did not copy the /usr/lib/python3.5 folder to the corresponding Android data folder.

This link was extremely useful - How does python find packages?

0
source

All Articles