Monkey Runner导入错误

时间:2011-09-26 06:57:24

标签: android monkeyrunner

我创建了一个名为something.py的空文件,然后我只是从android开发者网站复制了代码行。但是,如果我尝试运行它,我会得到一个

ImportError:没有名为com.android.monkeyrunner的模块

我有什么遗失的吗? android开发者网站上似乎没有解决此问题的任何内容。以下是代码行

       from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
       device = MonkeyRunner.waitForConnection()
       device.installPackage('myproject/bin/Stamp_Client.apk')
       package = 'com.example.main'
       activity = 'com.example.Stamp_Client'
       runComponent = package + '/' + activity
       device.startActivity(component=runComponent)
       device.press('KEYCODE_BUTTON_SELECT','DOWN_AND_UP')
       device.press('KEYCODE_U','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_E','DOWN_AND_UP')
       device.press('KEYCODE_R','DOWN_AND_UP')
       device.press('KEYCODE_ENTER','DOWN_AND_UP')
       device.press('KEYCODE_P','DOWN_AND_UP')
       device.press('KEYCODE_A','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_S','DOWN_AND_UP')
       device.press('KEYCODE_ENTER','DOWN_AND_UP')
       device.press('KEYCODE_ENTER','DOWN_AND_UP')

2 个答案:

答案 0 :(得分:4)

确保你跑:

$ monkeyrunner yourfile.py

而不是:

$ python yourfile.py

答案 1 :(得分:3)

我猜你错过了shebang

#! /usr/bin/env monkeyrunner

如果您使用的是Linux或OSX,对于Windows,您可能需要创建一个批处理文件。