KoljaB / Linguflex

Command Your World with Voice
439 stars 46 forks source link

"Failed to acquire X connection: Can't connect to display" #11

Open maxcurrent420 opened 4 months ago

maxcurrent420 commented 4 months ago

Installed on Linux and after having to install a number of dependencies left out of the requirements.txt I got this error on startup:

/python3.10/site-packages/pynput/_util/__init__.py", line 77, 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

Now, I don't know why I need an x server going, but more importantly how do I set it as an environment variable, assuming I get one on here? I just assumed once I installed it and got the llm going it would open a browser tab :D

KoljaB commented 4 months ago

I wasn't aware this needs an X Server running on linux. Since pynput is used in linguflex only for keyboard input handling (specifically to listen for the Escape key press and abort TTS in that case) it's probably best to switch to another keyboard handler.

In lingu.py replace:

from pynput import keyboard

with

import keyboard

Then replace

self.listener = keyboard.Listener(on_press=self.on_press)
self.listener.start()

with

keyboard.on_press_key("esc", self.on_press)

And finally replace

    def on_press(self, key):
        """
        Function called when a key is pressed.
        If Escape key is pressed, a message is printed.
        """
        if key == keyboard.Key.esc:
            events.trigger("escape_key_pressed", "ui")
            return True

with

    def on_press(self, key):
        events.trigger("escape_key_pressed", "ui")

This should solve the problems.

KoljaB commented 4 months ago

I committed the changes into the repo, the changed file is now here:

https://github.com/KoljaB/Linguflex/blob/main/lingu/core/lingu.py