Próbuję uruchomić skrypt python hello.py
z poziomu procesu Android.Uruchamianie hello.py z poziomu procesu Android
Oto kroki, jakie następuje:
- Mam zamówione binaria Python i przedmioty związane bibliotek.
- Przetestowałem je i pracują w emulatorze terminalu.
- Dodałem je do mojego folderu zasobów i skopiowałem je do prywatnego magazynu i utworzyłem je jako pliki wykonywalne.
Ale nadal pojawia się następujący błąd:
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):
Oto kod używany do wykonywania pliku.
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);
}
Co robię źle? Jak mogę to uruchomić?
'Nie można uzyskać encoding' lokalizacji' no moduł o nazwie „encodings''. Cóż ... gdzie to jest? – greenapps
@greenapps Nie mam pojęcia. To prosty helloworld.py. –
Komunikat o błędzie nie zależy od skryptu, ale myślę, że podczas inicjowania Pythona. Możesz równie dobrze podać nazwę nieistniejącego skryptu, który myślę. – greenapps