Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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