Skip to content

Instantly share code, notes, and snippets.

@nikhita
Created April 26, 2020 15:41
Show Gist options
  • Save nikhita/d09aea5ea4eaec8134f335bb32faf8f1 to your computer and use it in GitHub Desktop.
Save nikhita/d09aea5ea4eaec8134f335bb32faf8f1 to your computer and use it in GitHub Desktop.
gtk: "No protocol specified" error on Linux as root user

GTK protocol error

Problem

If you are running as a root user while opening a GTK session on Linux i.e. using sudo, su, etc, you might encounter errors like:

No protocol specified
/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
No protocol specified
Unable to initialize gtk: could not open display, falling back to console.

Why it occurs

This occurs generally due to Wayland. The root user does not have permissions to run programs in the current session.

Solution

Run xhost + local: to allow other users (including root) to run programs in the current session.

Try running your program again now, it should work! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment