ImportError: No module named 'com.android'
Asked Answered
F

2

7

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?

Fairweather answered 17/7, 2013 at 6:12 Comment(0)
S
8

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.

Surbase answered 18/7, 2013 at 19:35 Comment(4)
I tried to set preferences just by your tutorial, but got error messages like this: err1, err2Fairweather
I've replaced the latest version of PyDev with 1.6.5 and first error message has gone, but it still doesn't see interpreter's locationFairweather
Is there an option to use MonkeyRunner in PyCharm IDE?Serpens
You should use AndroidViewClient/culebra with Pychar as it is python based.Surbase
P
1

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)

Plainsman answered 17/7, 2013 at 6:30 Comment(1)
I got this log: ['D:\\MonkeyRunnerTest\\test', 'C:\\Python33\\lib\\site-packages\\distribute-0.6.27-py3.3.egg', 'C:\\android-sdk\\sdk\\tools\\lib\\monkeyrunner.jar', 'D:\\MonkeyRunnerTest', 'C:\\android-sdk\\sdk\\tools\\lib', 'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages', 'C:\\Python33\\lib\\site-packages\\setuptools-0.6c11-py3.3.egg-info'] Looks like monkeyrunner path was added in proper wayFairweather

© 2022 - 2024 — McMap. All rights reserved.