moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

Can't connect to X #351

Closed joaomamede closed 3 years ago

joaomamede commented 3 years ago

I was running an old script (late 2019) and now I have this error when importing pynput.

Any advice?

In [1]: import pynput                                                           
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-647deee2930e> in <module>
----> 1 import pynput

~/.local/lib/python3.8/site-packages/pynput/__init__.py in <module>
     38 
     39 
---> 40 from . import keyboard
     41 from . import mouse

~/.local/lib/python3.8/site-packages/pynput/keyboard/__init__.py in <module>
     29 
     30 
---> 31 backend = backend(__name__)
     32 KeyCode = backend.KeyCode
     33 Key = backend.Key

~/.local/lib/python3.8/site-packages/pynput/_util/__init__.py in backend(package)
     74                 resolutions.append(RESOLUTIONS[module])
     75 
---> 76     raise ImportError('this platform is not supported: {}'.format(
     77         '; '.join(str(e) for e in errors)) + ('\n\n'
     78             'Try one of the following resolutions:\n\n'

ImportError: this platform is not supported: ('failed to acquire X connection: Can\'t connect to display ":0": b\'No protocol specified\\n\'', DisplayConnectionError(':0', b'No 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
moses-palmer commented 3 years ago

I suggest a search on the term can't connect to display no protocol specified.

I would first test running the script from a terminal application launched from the DE---that way, you will have all X related environ variables set correctly. Have you updated you system since 2019 and started using Wayland? If so, you will only be able to interact with applications launched under Xwayland.

I will close this issue, as it is not directly related to this library, but feel free to continue commenting.