Python键盘模块OsError13

时间:2019-08-31 20:37:17

标签: python-3.x macos keyboard

我正在尝试学习有关python的所有知识。所以自然而然地,我安装了一些软件包(凹凸不平,熊猫,sicpy和键盘)。我当时在玩keyboard程序包,但一直得到OSError 13。我见过人们也有同样的问题,但是没人能给出确切的解决方法。

我环顾了GitHub和其他内容。 GitHub上有一个线程从2018年开始出现同样的问题,但同样没有确定的答案。

这是我不断收到的错误消息:

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运行它。

1 个答案:

答案 0 :(得分:0)

在终端中,您的代码应与

一起使用

sudo python3 your_script.py