2016-07-19 205 views
5

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:

  1. ho acquistati binari pitone e hanno bisogno di librerie collegate.
  2. Li ho testati e funzionano nell'emulatore di terminale.
  3. 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?

+0

'Impossibile ottenere il locale encoding'' Nessun modulo denominato 'encodings''. Bene ... dov'è? – greenapps

+0

@greenapps Non ne ho idea. È un semplice helloworld.py. –

+0

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

risposta

0

Questa era pura idiozia. Dopo giorni passati a tirare i capelli, ho finalmente scoperto cosa è andato storto. Non ho copiato la cartella /usr/lib/python3.5 nella cartella dati Android appropriata.

Questo collegamento è stato estremamente disponibile - How does python find packages?

+0

dal 19 luglio è durata più di cinque ore ;-)! – greenapps

+0

@greenapps L'ho lasciato cadere per un po '. Hehe. Modificato. –

Problemi correlati