1

I have a RaspberryPi with a PiTFT 3.5 display connected. The display is configured to mirror the HDMI output and the Pi is running Raspbian desktop.

Now what I am trying to do is to run a python program on the desktop but start it over the ssh connection. The problem is that when I just run my python script over the terminal as such:

sudo python3 /usr/local/project/main.py

it gives the following error:

_tkinter.TclError: no display name and no $DISPLAY environment variable

So is there a way of starting the python program on the desktop through ssh or maybe passing the display variable to Tkinter so that the program displays on my PiTFT screen.

1 Answer 1

1

Before you launch the script from ssh:

export DISPLAY=:0

There are other possible values but, presuming there is only one GUI user logged in on the pi, it will be :0, the first display. You can also get it directly from the desktop (echo $DISPLAY) -- but not from the ssh login.

2
  • Perfect it works, the only thing I had to change is to not run it as superuser and run your command and then it worked perfectly.
    – Mercury
    Sep 19, 2019 at 7:54
  • $DISPLAY is an environment variable, if you are curious. The export command is a shell built-in.
    – goldilocks
    Sep 19, 2019 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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