i'm using raspbian Jessie on the raspberry PI3, when I try to run my code, that is a GUI written in Python, it gives me this error:

erle@erle-brain:~ $ sudo python provaGUI.py
Traceback (most recent call last):
  File "provaGUI.py", line 8, in <module>
    finestra = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "hostname:0"

I already installed XQuarz on my macbook pro (High Sierra 10.13.1). Then I installed these packages on the raspberry:

sudo apt-get --no-install-recommends install xserver-xorg xserver-xorg-video-fbdev xinit pciutils xinput xfonts-100dpi xfonts-75dpi xfonts-scalable

but the error persist.

I read on the raspberry forum that :

1)I need to start up in GUI mode after reboot (but I don't know how I can do it)

2)I need to enter the GUI mode under the same login as the ssh connection (I don't know how to do it with command line)

3) the you need to execute at the ssh connection: export DISPLAY=:0.0

when I write startx on the raspberry this is the ouput but I don't know how to proceed:

    erle@erle-brain:~ $ sudo startx

X.Org X Server 1.18.4
Release Date: 2016-07-19
X Protocol Version 11, Revision 0
Build Operating System: Linux 4.4.26-v7+ armv7l Raspbian
Current Operating System: Linux erle-brain 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l
Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000  dwc_otg.lpm_enable=0 console=tty1,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Build Date: 11 November 2016  11:59:59AM
xorg-server 2:1.18.4-2+rpi1 (https://www.debian.org/support) 
Current version of pixman: 0.33.3
    Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sun Dec  3 18:08:15 2017
(==) Using system config directory "/usr/share/X11/xorg.conf.d"

Any advice for this problem??


If you are connecting to a remote host via ssh and would like the graphical interface to show on your local display, you need to:

  1. Have Xwindows running on the local host.
  2. Enable X11Forwarding in sshd_config
  3. Use the -X option with ssh

$ssh -X pi@raspberrypi.local

Simple Debugging of X11 SSH Connection

There is no need to start X11 manually on the Mac side. If you use the -vv option when trying to connect via ssh, you'll get useful debugging messages.

Towards the end of messages, you'll notice that X11 is started automatically:

$ ssh -vvX pi@
OpenSSH_5.9p1, OpenSSL 0.9.8zg 14 July 2015
debug1: Reading configuration data /etc/ssh_config
debug1: Next authentication method: password
pi@'s password: 
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
Authenticated to ([]:22).
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug2: callback start
debug2: Checking for xauth using /opt/X11/bin/xauth -f /var/folders/8m/1xj8bn_5207362cdqqjh0fgc0000gp/T//xauth_test exit > /dev/null 2> /dev/null

debug2: x11_get_proto: /opt/X11/bin/xauth -f /var/folders/8m/1xj8bn_5207362cdqqjh0fgc0000gp/T//ssh-44sR13L9kqIX/xauthfile generate /tmp/launch-2GDFN0/org.macosforge.xquartz:0 MIT-MAGIC-COOKIE-1 untrusted timeout 1200 2>/dev/null
debug2: x11_get_proto: /opt/X11/bin/xauth -f /var/folders/8m/1xj8bn_5207362cdqqjh0fgc0000gp/T//ssh-44sR13L9kqIX/xauthfile list /tmp/launch-2GDFN0/org.macosforge.xquartz:0 2>/dev/null
debug1: Requesting X11 forwarding with authentication spoofing.
debug2: channel 0: request x11-req confirm 1
debug2: client_session2_setup: id 0
debug2: fd 3 setting TCP_NODELAY
debug2: channel 0: request pty-req confirm 1
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug2: channel 0: request env confirm 0
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug2: channel_input_status_confirm: type 99 id 0
debug2: X11 forwarding request accepted on channel 0
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 0
debug2: shell request accepted on channel 0
Linux raspberrypi 4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Dec  4 09:02:38 2017 from
pi@raspberrypi:~ $ 

MacOSx and Debian Trusted X11

For some configurations, there is a problem with Trusted connections. The SSH man page suggests that some programs may crash when connecting to Debian systems. Raspbian is a Debian variant. So, it's possible that you will need to follow the Debian specific advice in the ssh man page:

(Debian-specific: This option does nothing in the default configuration: it is equivalent to “ForwardX11Trusted yes”, which is the
         default as described above.  Set the ForwardX11Trusted option to “no” to restore the upstream behaviour.  This may change in future
         depending on client-side improvements.)

And change or add the following line in /etc/ssh/sshd_config on the Raspberry Pi:

ForwardX11Trusted no

For further reading on the MacOSx X11 auth problem:

ServerFault:What does “Warning: untrusted X11 forwarding setup failed: xauth key data not generated” mean when ssh'ing with -X?

  • Thank you for your answer: So I did 1) sudo startx in my terminal of macbook 2) enable X11Forwarding in both macbook and raspberry with the command 'sudo nano /etc/ssh/sshd_config' 3) ssh -X erle@ip-adress BUT when I ssh into the raspberry with the "-X" nothing happened – flavia13 Dec 4 '17 at 9:33
  • The sudo startx in my terminal of macbook give me this is the "error": 'xauth: file /Users/flavia/.serverauth.2189 does not exist' – flavia13 Dec 4 '17 at 9:47
  • @flavia13 : Added some debugging messages which may be helpful. – RubberStamp Dec 4 '17 at 14:23
  • Thank you! That was very useful, I did the ssh and everything works fine, except for this warning: "Warning: untrusted X11 forwarding setup failed: xauth key data not generated". Then I tried to python myscript.py (it's a GUI that use tkinter) but gives me this error: " _tkinter.TclError: no display name and no $DISPLAY environment variable " . Infact the command 'echo $DISPLAY' doesn't give me any output. What can I do? Thank you for the patience – flavia13 Dec 4 '17 at 15:52
  • Also, I tried to do: ~ $ export DISPLAY=:0.0 and then: 'sudo python provaGUI.py' but the program crashed and I had to reboot the raspberry. – flavia13 Dec 4 '17 at 15:59

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.