Monkey Runner 导入出现错误

发布于 2024-12-06 18:07:49 字数 1173 浏览 1 评论 0原文

我创建了一个空文件,并将其命名为 Something.py,然后我只是从 Android 开发者网站复制了代码行。但是,如果我尝试运行它,我会收到一个

ImportError: No module named 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')

i created an empty file an named it something.py, and then i just copied the lines of code from the android developer website. However, if i try to run it, i get an

ImportError: No module named com.android.monkeyrunner

Is there something i am missing? There doesn't seem to be anything at the android developer website that addresses this issue. Here are the lines of code

       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')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平生欢 2024-12-13 18:07:49

确保运行:

$ monkeyrunner yourfile.py

而不是:

$ python yourfile.py

Make sure you run:

$ monkeyrunner yourfile.py

instead of:

$ python yourfile.py
半山落雨半山空 2024-12-13 18:07:49

我猜你错过了 shebang

#! /usr/bin/env monkeyrunner

也就是说,如果你使用的是 Linux 或 OSX ,对于 Windows,您可能必须创建一个批处理文件。

I guess you are missing the shebang:

#! /usr/bin/env monkeyrunner

that is if you are using Linux or OSX, for Windows you probably have to create a batch file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文