moses-palmer / pynput

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

* Please make sure that you have an X server running, and that the DISPLAY environment variable is set correctly #518

Closed abirabedinkhan closed 1 year ago

abirabedinkhan commented 1 year ago

When I try to run the script

Traceback (most recent call last):
  File "/home/abirabedinkhan/Desktop/RFID/app.py", line 1, in <module>
    import pynput
  File "/home/abirabedinkhan/Desktop/RFID/env/lib/python3.10/site-packages/pynput/__init__.py", line 40, in <module>
    from . import keyboard
  File "/home/abirabedinkhan/Desktop/RFID/env/lib/python3.10/site-packages/pynput/keyboard/__init__.py", line 31, in <module>
    backend = backend(__name__)
  File "/home/abirabedinkhan/Desktop/RFID/env/lib/python3.10/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: No module named 'tkinter'", ModuleNotFoundError("No module named 'tkinter'"))

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
perroboc commented 1 year ago

https://www.geeksforgeeks.org/how-to-install-tkinter-on-linux/

abirabedinkhan commented 1 year ago

I did all of those. Btw, I am trying to use it with ssh.

moses-palmer commented 1 year ago

Thank you for your report.

When you say that you are trying to use it with SSH, do you mean that you intend to control/monitor a remote computer? In that case you must have an X server running remotely, and you must ensure that the DISPLAY environment variable is correctly set in the remote shell.

The error message, however, appears very strange: "No module named 'tkinter'". This happens when pynput attempts to import pynput._util.xorg, which does not import Tkinter.

dp-alvarez commented 1 year ago

The No module named 'tkinter' message is probably because on debian there are some parts of the stdlib missing on a default python install. Just apt-get install python3-tk. Not sure about other distros.

Nothing really to be done on Pynput I think, other than maybe adding a line about it in the docs.

abirabedinkhan commented 1 year ago

Yeah did install apt-get install python3-tk before running my script. I encountered this problem before in my VM.apt-get install python3-tk fixed my problem there. However, when I am trying through ssh it shows the same error whether apt-get install python3-tk installed or not. How do I set the DISPLAY environment variable?

perroboc commented 1 year ago

did you connect with -X argument? or are you using putty? remember the linux installation must have a display server installed (x org for example). https://www.baeldung.com/linux/forward-x-over-ssh is a good tutorial

El mar, 29 nov 2022 a la(s) 22:48, Abir Abedin Khan - notifications at github.com @.***) escribió:

Yeah did install apt-get install python3-tk before running my script. I encountered this problem before in my VM.apt-get install python3-tk fixed my problem there. However, when I am trying through ssh it shows the same error whether apt-get install python3-tk installed or not. How do I set the DISPLAY environment variable?

— Reply to this email directly, view it on GitHub https://github.com/moses-palmer/pynput/issues/518#issuecomment-1331541464, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUYXVMKRL5CKYGSH3LIEJTWK2W6RANCNFSM6AAAAAASDT3SY4 . You are receiving this because you commented.Message ID: @.***>

abirabedinkhan commented 1 year ago

It's a armbian desktop.

moses-palmer commented 1 year ago

In that case perhaps there easiest solution would be to open a terminal window in the desktop session and run the command echo $DISPLAY. Then, when you have SSH'd into the armbian host, launch your program thus: DISPLAY=[output of echo command] python3 app.py.

dodgyrabbit commented 1 year ago

FYI the root cause of this exception is here: https://github.com/python-xlib/python-xlib/issues/240

In 0.33 it no longer happens