从Android进程中运行hello.py

时间:2016-07-19 07:54:22

标签: android python

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

以下是我遵循的步骤:

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

    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):
    

    以下是用于执行文件的代码。

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

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

1 个答案:

答案 0 :(得分:0)

这是纯粹的白痴。经过几天的拔毛,我终于发现了什么问题。我没有将(gimp-image-width 1) (400) 文件夹复制到相应的Android数据文件夹中。

此链接非常有用 - How does python find packages?