I have a GUI app that I can run from a terminal window on a Raspberry Pi desktop and it displays the GUI output on the screen attached to the HDMI port. In the terminal window I run a command like python myapp.py

If at the same time I am logged in to another computer with an ssh terminal back to the RPi, if I run python myapp.py it fails because it can't connect to the display.

I imagine that it must be possible to do this, and perhaps the python myapp.py needs to be wrapped in a script that supplies appropriate environment variables.

What's the best way to solve this?

  • If your "other computer" runs an X-Windows server (default if using Linux with a GUI) then you can use X-forwarding (-X option in the ssh command). – xenoid Dec 25 '18 at 10:26
  • 1
    Welcome to Unix & Linux Stack Exchange.  It would appear that you have accidentally created two accounts. This will interfere with commenting, editing your own posts, and accepting an answer. You should use the contact form and select “I need to merge user profiles” to have your accounts merged.  In order to merge them, you will need to provide links to the two accounts.  For your information, these are unix.stackexchange.com/users/328379/patrick-h (Patrick H) and unix.stackexchange.com/users/328428/padraig-h (Padraig H). You’ll then be able to edit your question. – G-Man Dec 26 '18 at 2:08

As mentioned in comments, assuming the remote machine is running X Window Server, you can redirect the display to this machine using -X:

From man page:

-X Enables X11 forwarding.

So from remote host:

ssh user@raspberry -X

Then simply run your app:

python myapp.py
  • In response to Kevin... I tried doing 'ssh -X me@RPi as suggested, and then ran the 'python myapp.py' command, but I get an error: pygame.error: Unable to open a console terminal – Padraig H Dec 25 '18 at 17:14

You need to start an X server on your Raspberry Pi, then just type in DISPLAY=:0 python myapp.py into your SSH session. It should start.



Interestingly, it was not necessary to use the -X argument...

From the remote system:

ssh RPi

Then do:

DISPLAY=:0 python myapp.py

Thanks to both responders!

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.