Sto provando a eseguire uno script python hello.py
da un processo Android.Esecuzione hello.py da un processo Android
qui sono i passi che ho seguito:
- ho acquistati binari pitone e hanno bisogno di librerie collegate.
- Li ho testati e funzionano nell'emulatore di terminale.
- Li ho aggiunti alla mia cartella di asset e li ho copiati nell'archivio privato e li ho resi eseguibili.
Ma ancora ottengo il seguente errore:
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):
Ecco il codice utilizzato per eseguire il file.
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);
}
Cosa sto sbagliando? Come faccio a far funzionare questo?
'Impossibile ottenere il locale encoding'' Nessun modulo denominato 'encodings''. Bene ... dov'è? – greenapps
@greenapps Non ne ho idea. È un semplice helloworld.py. –
Il messaggio di errore non dipende dal tuo script, ma penso all'inizializzazione di python. Potresti anche fornire il nome di uno script non esistente, credo. – greenapps