Wednesday, 7 August 2013

How does Python (or MonkeyRunner) locate imported modules?

How does Python (or MonkeyRunner) locate imported modules?

I have two .py files in the same directory: screenshots.py and util.py. I
need to run screenshots.py with the monkeyrunner interpreter from the
Android build tools. When I run monkeyrunner screenshots.py, I get error
No module named util. How do I configure my python and/or monkeyrunner to
find the code in util.py?
For reference, this is the complete error message:
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an
exception
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call
last):
File
"c:\Users\Dell\Documents\dev\src\java\bbct\android\functional-tests\screenshots.py",
line 19, in
import util
ImportError: No module named util
130807 12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.ImportError(Py.java:264)
130807 12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.import_first(imp.java:657) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.import_name(imp.java:741) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.importName(imp.java:791) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.ImportFunction.call(_builtin_.java:1236) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyObject.call(PyObject.java:367) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.builtin._import_(builtin.java:1207) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.builtin._import_(builtin.java:1190) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.imp.importOne(imp.java:802) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at
org.python.pycode._pyx0.f$0(c:\Users\Dell\Documents\dev\src\java\bbct\android\functional-tests\screenshots.py:51)
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]
at
org.python.pycode._pyx0.call_function(c:\Users\Dell\Documents\dev\src\java\bbct\android\functional-tests\screenshots.py)
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyTableCode.call(PyTableCode.java:165) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.PyCode.call(PyCode.java:18) 130807 12:01:59.978:S
[main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.Py.runCode(Py.java:1197) 130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.core.builtin.execfile_flags(builtin.java:538) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116) 130807
12:01:59.978:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
at
com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)
130807 12:01:59.978:S [main]
[com.android.monkeyrunner.MonkeyRunnerOptions]
at
com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189)

No comments:

Post a Comment