Ask coding questions

← Back to all posts
Why does the pynput module not work?
RhinoRunner (866)

I am trying to get mouse input in python, so I tried the pynput module to test it out.
This is what happened.

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import pynput
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pynput/__init__.py", line 40, in <module>
    from . import keyboard
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/pynput/keyboard/__init__.py", line 31, in <module>
    backend = backend(__name__)
  File "/opt/virtualenvs/python3/lib/python3.8/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 'Xlib'", ModuleNotFoundError("No module named 'Xlib'"))

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

Can anyone tell me what's wrong with it or if there is another module I can use for mouse input in the terminal?

Answered by SixBeeps (5223) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5223)

Mouse input in the terminal? That doesn't exist. Terminals have never had that kind of capability, in or out of Replit.

If you want to use the mouse, you'll have to set up the X11 VNC. Usually I've been able to do this with the polygott-x11-vnc command, but it appears to not be working now.

firefish (947)

I think I know what's happened: the X server (which is the graphics server that repl.it and most linux machines use) doesn't seem to be set up properly. Try opening a different kind of python repl, preferably something with graphics support, like Python with Tkinter. click here to create a repl

Note: this is Python 3.6, not the latest 3.9.

InvisibleOne (2935)

It needs to be made in a repl with an Xserver, try doing it in pygame, tinker, or turtle I think.