0

当我在 Mac 上的 Jupyter Notebook 中运行以下代码时

import keyboard
if keyboard.is_pressed('q'):
    print("Yes")

它显示以下错误:

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/mayankmalviya64/opt/anaconda3/lib/python3.7/site-packages/keyboard/__init__.py", line 294, in listen
    _os_keyboard.listen(self.direct_callback)
  File "/Users/mayankmalviya64/opt/anaconda3/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

由于在 MacOS 上,以管理员身份运行选项不像 Windows 那样可用,我该怎么办?我想检测按键,就像按下键盘上的任意键一样,程序停止!

I have also tried to run the above code through my terminal in iPython. It shows the same error there too.
4

1 回答 1

0

您可以使用终端使用此命令打开它

sudo open /Users/<your-username>/Applications/Anaconda

如果您更改,请使用正确的目录

于 2020-05-16T00:58:08.010 回答