我正在尝试hello.py从Android进程中运行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):
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)
我究竟做错了什么?我如何让它工作?
这纯粹是愚蠢的行为。经过几天的拉扯头发,我终于发现出了问题所在。我没有将该/usr/lib/python3.5文件夹复制到相应的 Android 数据文件夹中。
这个链接非常有帮助 - How does python find packages?
| 归档时间: |
|
| 查看次数: |
115 次 |
| 最近记录: |