【发布时间】:2020-01-29 00:34:04
【问题描述】:
我正在努力学习有关 python 的所有知识。所以很自然地我安装了一些包(bumpy、pandas、sicpy 和键盘)。我一直在玩keyboard 包,但我不断收到OSError 13。我见过有人遇到同样的问题,但没有人给出关于如何解决这个问题的明确答案。
我在 GitHub 上四处寻找。从 2018 年开始,GitHub 上有一个线程存在同样的问题,但同样没有明确的答案。
这是我不断收到的错误消息:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keyboard/__init__.py", line 292, in listen
_os_keyboard.listen(self.direct_callback)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator
这是实际的程序代码:
import keyboard # using module keyboard
while True: # making a loop
try: # used try so that if user pressed other than the given key error will not be shown
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('You Pressed A Key!')
break # finishing the loop
else:
pass
except:
break # if user pressed a key other than the given key the loop will break
错误信息在代码中。我也是菜鸟,所以如果已经回答了这个问题,是否有人可以链接到该答案。另外:我在 Mac OS 上使用 IDLE 运行它。
【问题讨论】:
-
错误可能与 IDLE 或任何 IDE 无关。可以肯定的是,在 TerminaI 中使用 'python3' 运行 python 并在 python 的 '>>>' 提示符下输入 'import terminal'。如果您不理解“以管理员身份运行”,请在网络上搜索“以管理员身份运行 macOS”。我很确定在导入过程中会发生错误。因此建议自行运行“导入键盘”。
-
这能回答你的问题吗? Unable to run 'keyboard.is_pressed' on Mac
标签: python-3.x macos keyboard