How can we open Gtk and other gui apps via the command line with Wayland?

When I try to open a basic PyGTK script or Gedit I get this error:

chris@fluffie:~/workspace/wiki-web$ gedit
No protocol specified
Unable to init server: Could not connect: Connection refused
(gedit:13376): Gtk-WARNING **: cannot open display:

Setting $DISPLAY just changes the error a bit.
Most of the solutions I have found for this revolve around trying to run these applications as root and want you to run xhost:

chris@fluffie:~/workspace/wiki-web$ xhost si:localuser:root                                                                                 
xhost:  unable to open display ""

Which doesn't seem to help (since I think it is supposed to only alter permissions?)

Any ideas how I can launch my python scripts?

Adding tail of my .bashrc with the updates I have made to it:

# Make CapsLock behave like Ctrl
setxkbmap -option ctrl:nocaps
# make press-release CapsLock behave like Escape
xcape -e 'Control_L=Escape' -t 500
alias nose2="python3 /home/chris/.local/lib/python3.5/site-packages/nose2/__main__.py"
export PATH=$PATH:/home/chris/bin
export USER="chris" 
#export DISPLAY=":0"
#export DEPTH="16"
#export GEOMETRY="1280x1024"
#export OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"
export EDITOR="vim"
export SYSTEMD_EDITOR="/usr/bin/vim"
export TERM="tmux" 

Looks like it is a tmux issue. I can open gedit or my dinky python script via terminal if it is outside tmux. So I just need to figure out how to fix tmux (or why it is not possible to do this).

  • What you describe works for me in Ubuntu 17.10 with Wayland: the command gedit starts the GUI editor gedit. -- 1. My 17.10 system was made as a fresh installation (not upgraded) ; 2. I ran the command in a terminal window (not in a text screen). -- I know that there are several problems in 17.10 systems that are created by upgrading from previous versions (usually from 17.04). How did you create your 17.10 system? – sudodus Jan 13 '18 at 6:37
  • @pomsky, This problem seems to affect GUI programs that are run with standard permissions (without sudo). – sudodus Jan 13 '18 at 9:21
  • @sudodus Oh, I see... Sorry I overlooked the fact that OP is tried to run gedit, not sudo gedit. – pomsky Jan 13 '18 at 9:30
  • @sudodus Thanks, that means its something I did since installing. I will add a snippet of my .bashrc to the question. – Chris Jan 13 '18 at 14:32
  • 1
    Hey @sudodus, 1. I think yes, I haven't found a good way to determine, but I haven't explicitly turned xorg on. 2. This install is a few months old with some minor tinkering. 3. Don't recall why i am setting $USER, but for some reason I need to set $TERM to TMUX else I get some graphical artifacts in the tmux session. I can dig around for the details if you are interested. – Chris Jan 15 '18 at 0:53

You're right twice - it's a tmux issue, and most solutions just say to run as root, which is the wrong answer more often than not.

Tmux doesn't automatically import everything into its session. You can specify particular variables you want to be available in the session by using update-environment in your ~/.tmux.conf:

set -g update-environment 'DISPLAY TERM XAUTHORITY WINDOWID'

For SSH-related xhost issues, include SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION in that list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.