I am new to pynput and I'm running a basic script to test some functions out:
from pynput import keyboard
def on_key_press(key):
try:
print(f'Key pressed: {key.char}')
except AttributeError:
print(f'Special key pressed: {key}')
def on_key_release(key):
pass
with keyboard.Listener(on_press=on_key_press, on_release=on_key_release) as listener:
listener.join()
But when I ran it gave the following error:
Traceback (most recent call last):
File "/home/voldemort/projects/pynput_tutorial/main.py", line 1, in <module>
from pynput import keyboard
File "/home/voldemort/projects/pynput_tutorial/venv/lib/python3.11/site-packages/pynput/__init__.py", line 40, in <module>
from . import keyboard
File "/home/voldemort/projects/pynput_tutorial/venv/lib/python3.11/site-packages/pynput/keyboard/__init__.py", line 31, in <module>
backend = backend(__name__)
^^^^^^^^^^^^^^^^^
File "/home/voldemort/projects/pynput_tutorial/venv/lib/python3.11/site-packages/pynput/_util/__init__.py", line 76, in backend
raise ImportError('this platform is not supported: {}'.format(
ImportError: this platform is not supported: ('failed to acquire X connection: Can\'t connect to display ":0": b\'Authorization required, but no authorization protocol specified\\n\'', DisplayConnectionError(':0', b'Authorization required, but no authorization protocol specified\n'))
Try one of the following resolutions:
* Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly
I'm running this on fedora linux 38, gnome 44.3, wayland.
How can I fix this?