question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Xlib.error.DisplayConnectionError on Ubuntu 18.04

See original GitHub issue

Importing pyautogui in Python 3.7.2 in Ubuntu 18.04, generates a Xlib.error.DisplayConnectionError This error only occurs when running python with superuser privileges.

This the full traceback :-

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/pyautogui/__init__.py", line 152, in <module>
    from . import _pyautogui_x11 as platformModule
  File "/usr/local/lib/python3.7/site-packages/pyautogui/_pyautogui_x11.py", line 160, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/usr/local/lib/python3.7/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/local/lib/python3.7/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/usr/local/lib/python3.7/site-packages/Xlib/protocol/display.py", line 167, in __init__
    raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n

Steps to reproduce:-

  • run sudo python3 in the terminal
  • run import pyautoguiinside the python 3 shell

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

4reactions
iojcdecommented, Jul 21, 2020

Try https://github.com/mooz/xkeysnail/blob/master/README.md (look at usage section)

worked for me.

2reactions
Axaxincommented, Feb 8, 2022

Same issue on ubuntu 20.04 python 3.8.10 system is on a VM, connect via noVNC… i think this is very common situation using linux, isnt it?

ok, issue resolve by installing python-tk (not python3-tk), then restart terminal or system, then it works. As the installation guide, i did install acrot, python3-tk and python3-dev, but it turn out not working, I’m not sure if I had restarted terminal right after these packs install, but I did restart after python-tk, then everything work.

Not sure if both python3-tk and python-tk are needed, or just python-tk alone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix error Xlib.error.DisplayConnectionError: Can't ...
On my PC with Ubuntu 14.04 everything works fine but when I try to run my app in my notebook with manualy installed...
Read more >
Python Xlib applications report 'Can't connect to display ":0"
Bug Description. The python-xlib package does not appear to correctly use X11 cookies from $XAUTHORITY under Ubuntu 18.04 (and possibly others).
Read more >
python-xlib - Bountysource
DisplayConnectionError (dname, str(val)) Xlib.error. ... I was writing an automation script on Ubuntu 18.04 using python-xlib when I noticed that keycode ...
Read more >
Linux multiple monitor error? (with shaky workaround) - Support
Hi there, I tried to get AW to run on my Ubuntu 18.04 (Macbook Pro hardware), but I got this error repeatedly: 2018-10-08...
Read more >
xorg - How can I diagnose/debug "maximum number of clients ...
X11 -unix/X0 socket file; but there are lots more connections (displayed as ... Chromium/Chrome has some known issues which result in this error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found