Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'com.android'

I'm writing a simple test for Android app and it fails while trying to connect my device with this log:

Traceback (most recent call last):   File "D:/MonkeyRunnerTest/test/LaunchTest.py", line 3, in <module>
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice ImportError: No module named 'com'

I use Pycharm 2.7.3, Python 3.3.2, juthon-standalone-2.5.3. I've tried to launch my test project on Eclipse with PyDev and Intellij Idea with Python plug-in, but with the same result. Also I've added environment variable PYTHONPATH containing the path to monkeyrunner and jython source to my operation system (Windows 7), it didn't help.

Any suggestions for this issue?

like image 836
Nathaniele Eldritch Avatar asked Jul 17 '13 06:07

Nathaniele Eldritch


2 Answers

You should only use monkeyrunner interpreter to run monkeyrunner scripts. Forget about python, jython, etc.

From you command line try:

monkeyrunner LaunchTest.py

and it will work.

You can find some instructions to use monkeyrunner with Eclipse+Pydev. See the updates at the bottom of the page.

like image 114
Diego Torres Milano Avatar answered Sep 19 '22 18:09

Diego Torres Milano


Assuming you have the proper modules installed: They aren't in your system path. You can check your system path manually to see if the directory is there by doing

import sys
print sys.path

You can append to sys.path as you would any list, but it's probably better to modify it via your OS, rather than on the fly appending. (which is temporary, sys.path reverts to its original state after the end of the script in python)

like image 43
seth Avatar answered Sep 17 '22 18:09

seth