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
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.
-
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– Mercury2019年09月19日 07:54:34 +00:00Commented Sep 19, 2019 at 7:54
-
$DISPLAY
is an environment variable, if you are curious. Theexport
command is a shell built-in.goldilocks– goldilocks2019年09月19日 10:37:04 +00:00Commented Sep 19, 2019 at 10:37
Explore related questions
See similar questions with these tags.