2016-07-19 10 views
5

Próbuję uruchomić skrypt python hello.py z poziomu procesu Android.Uruchamianie hello.py z poziomu procesu Android

Oto kroki, jakie następuje:

  1. Mam zamówione binaria Python i przedmioty związane bibliotek.
  2. Przetestowałem je i pracują w emulatorze terminalu.
  3. 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ć?

+0

'Nie można uzyskać encoding' lokalizacji' no moduł o nazwie „encodings''. Cóż ... gdzie to jest? – greenapps

+0

@greenapps Nie mam pojęcia. To prosty helloworld.py. –

+0

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

Odpowiedz

0

To był czysty idiotyzm. Po dniach wyciągania włosów w końcu dowiedziałem się, co poszło nie tak. Nie skopiowałem folderu /usr/lib/python3.5 do odpowiedniego folderu danych Androida.

Ten link był bardzo pomocny - How does python find packages?

+0

Od 19 lipca minęło ponad pięć godzin ;-)! – greenapps

+0

@greenapps Upuściłem go na chwilę. Hehe. Edytowane. –

Powiązane problemy