I have the android emulator/SDK installed on my computer, and I'm trying to run a simple python script, but it fails on the 'import os' line (which should be standard!)
Here's my script:
import os
print os.environ['PATH']
works fine when I run it against the actual python executable as
python test.py
but when I do
monkeyrunner.bat test.py
I get the error listed in the title of this question. I've uninstalled/reinstalled python several times, with no luck. Tried adding a PYTHONPATH ENV varaible, no luck. Set the python install dir to be in the PATH ENV variable. Kind of at my wits end, I think monkeyrunner runs on jython but I don't know if I can manage the jython install that comes with the SDK
The solution of this problem (and the problem itself explained) can be found at http://dtmilano.blogspot.ca/2013/05/monkeyrunner-importerror-no-module.html.
Basically, you have to replace jython-2.5.3.jar
by jython-standalone-2.5.3.jar
, at least until Android SDK Tools Rev. 22.0.1 is out.
The issue is that the latest versions of the Android SDK include jython-2.5.3 which do not have the os and other importable libraries built in. I found an old copy of the SDK and used the old JAR which appears to have that embedded in it those libraries.
all by itself in the jython interpreter
If you're using the jython packaged with the Android SDK, it doesn't include an 'os' module by default. You'll need to grab one, and put it in there, or use another interpreter.
I resolved this issue with java 1.7.0_21.
来源:https://stackoverflow.com/questions/16596653/trying-to-run-simple-monkeyrunner-python-script-importerror-no-module-named-os