从Android进程中运行hello.py

Bin*_*abu 5 python android

我正在尝试hello.py从Android进程中运行python脚本.

以下是我遵循的步骤:

  1. 我已经购买了python二进制文件并需要链接库.
  2. 我测试了它们,他们正在终端模拟器中工作.
  3. 我已将它们添加到我的资产文件夹中,并将它们复制到私有存储中并使其可执行.

但是我仍然收到以下错误:

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):
Run Code Online (Sandbox Code Playgroud)

这是用于执行文件的代码.

    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);
    }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我如何让它工作?

Bin*_*abu 0

这纯粹是愚蠢的行为。经过几天的拉扯头发,我终于发现出了问题所在。我没有将该/usr/lib/python3.5文件夹复制到相应的 Android 数据文件夹中。

这个链接非常有帮助 - How does python find packages?