1

キーボードモジュールを使用していますが、このエラーが発生します。

私は他の投稿を見て、彼らが言うように実行し、sudo pip3 install キーボードを使用しましたが、それでも機能しません。

import keyboard
loop = ""


while loop == "":

    if keyboard.read_key() == "w":
        print("You pressed w")



    if keyboard.read_key() == "a":


        print("You pressed a")

    if keyboard.read_key() == "s":
        print("You pressed s")



    if keyboard.read_key() == "d":
        print("You pressed d")

>>> 
==================== RESTART: /home/pi/Desktop/turret.py ====================
Traceback (most recent call last):
  File "/home/pi/Desktop/turret.py", line 7, in <module>
    if keyboard.read_key() == "w":
  File "/usr/local/lib/python3.7/dist-packages/keyboard/__init__.py", line 935, in read_key
    event = read_event(suppress)
  File "/usr/local/lib/python3.7/dist-packages/keyboard/__init__.py", line 924, in read_event
    hooked = hook(queue.put, suppress=suppress)
  File "/usr/local/lib/python3.7/dist-packages/keyboard/__init__.py", line 461, in hook
    append(callback)
  File "/usr/local/lib/python3.7/dist-packages/keyboard/_generic.py", line 67, in add_handler
    self.start_if_necessary()
  File "/usr/local/lib/python3.7/dist-packages/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/usr/local/lib/python3.7/dist-packages/keyboard/__init__.py", line 196, in init
    _os_keyboard.init()
  File "/usr/local/lib/python3.7/dist-packages/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/usr/local/lib/python3.7/dist-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/usr/local/lib/python3.7/dist-packages/keyboard/_nixcommon.py", line 174, in ensure_root
    raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
>>> 

コードを実行すると、そのエラーが発生します。ルートにインストールしたと思いました。

4

1 に答える 1