在Android进程中运行hello.py

在Android进程中运行hello.py,android,python,Android,Python,我试图在Android进程中运行python脚本hello.py 以下是我遵循的步骤: 我已经购买了python二进制文件,需要链接库 我已经对它们进行了测试,它们正在终端模拟器中工作 我已将它们添加到我的资产文件夹中,并将它们复制到私人文件夹中 存储并使其可执行 但我仍然得到以下错误: 07-19 13:35:15.391 26991-26991/com.vibhinna.example I/System.out: Here is the standard output of the comm

我试图在Android进程中运行python脚本
hello.py

以下是我遵循的步骤:

  • 我已经购买了python二进制文件,需要链接库
  • 我已经对它们进行了测试,它们正在终端模拟器中工作
  • 我已将它们添加到我的资产文件夹中,并将它们复制到私人文件夹中 存储并使其可执行
  • 但我仍然得到以下错误:

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

    我做错了什么?我怎么才能让它工作呢?

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


    此链接非常有用-

    无法获取区域设置编码
    没有名为“encodings”的模块
    。好。。。它在哪里?@greenapps我不知道。这是一个简单的helloworld.py。我认为错误消息并不取决于脚本,而是取决于初始化python。我想你也可以提供一个不存在的脚本的名称。@greenapps我也是这么想的。你知道是什么影响了初始化吗?@greenapps找到了解决方案,从7月19日开始,已经持续了五个多小时;-)@我把它扔了一会儿。呵呵。编辑。