Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing MonkeyRunner into Python script fails in Windows

Why importing MonkeyRunner into Python script fails in Windows?

I created a file foo.py and copy-pasted code from the MonkeyRunner docs. The following error appears when compiling the sample code in cmd line:

Traceback (most recent call last):
  File "foo.py", line 2, in 
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
ImportError: No module named com.android.monkeyrunner


The Android tools folder has monkeyrunner.jar... and I fail to understand how to tell Python to import classes from it.


Follow-up

I found out the error came because I didn't have the latest Android tools (16).

  1. Update to newest tools (16) & platform (15) first
  2. Add android-sdk\tools into path
  3. Put foo.py into android-sdk\tools folder (it doesn't seem to work anywhere else)
  4. Switch usb debugging on
  5. Attach phone to PC
  6. Type "monkeyrunner foo.py"
like image 313
Jarno Argillander Avatar asked Feb 09 '12 10:02

Jarno Argillander


1 Answers

A) MonkeyRunner uses Jython, so you must make sure you have that installed

B) Jython must know where MonkeyRunner is. You can either have the script at the same place as where MonkeyRunner is located, or you can add it to Jython's path, so Jython will be able to find it no matter where you run the script from.

like image 115
Ivo Avatar answered Sep 22 '22 09:09

Ivo