Posts: 5
Joined: Tue Nov 06, 2012 2:35 am

Running python script from SSH

Tue Mar 05, 2013 12:46 am

Hi there,

I have a python script I have been writing which slideshows images on my R-Pi, I'd like to be able to run it from SSH if possible.

When I run the script with

> python

I get an error...

Code: Select all

Traceback (most recent call last):
  File "", line 65, in <module>
    root = MyApp()
  File "", line 7, in __init__
  File "/usr/lib/python2.7/lib-tk/", line 1688, in __init__ = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
I am guessing this is something to do with the way I am connected remotely and the desktop are separate?

Is it possible to run the script via SSH and have it affect the desktop?

Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: Running python script from SSH

Tue Mar 05, 2013 2:42 am

programs that use GUIs cant be started from SSH terminal, either start it on the raspberry pi or through vnc server
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P

User avatar
Posts: 3409
Joined: Tue Oct 11, 2011 8:38 pm

Re: Running python script from SSH

Tue Mar 05, 2013 2:55 am

If you have already logged in on the Pi and started X, over SSH you can do:

Code: Select all

DISPLAY=:0 python
(With most GUI programs this is not very useful, because you need the Pi's mouse and keyboard to control the program so you may as well start it using them. However, it might make sense for a slideshow, or any program that needs no control or can be controlled remotely.)

Forum Moderator
Forum Moderator
Posts: 5164
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Running python script from SSH

Wed Mar 06, 2013 9:36 pm

Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):

Posts: 20
Joined: Thu Feb 21, 2013 2:03 pm

Re: Running python script from SSH

Fri Mar 08, 2013 3:31 pm

cae2100 is I'm afraid wrong.

Programs that use a GUI can definitely be run over ssh, by including the -X switch in the ssh command.
For instance
ssh -X
Note that the X has to be a cap (lower case x means something else).

Return to “Python”