zweiundvierzig
Posts: 3
Joined: Fri Apr 15, 2016 3:47 pm

Execute python from desktop

Fri Apr 15, 2016 4:17 pm

Hi everyone,
maybe it's just me being stupid or looking for answers by asking the wrong questions ;) Anyway, I am a complete beginner using Raspi (did some Arduino before, know programming on Windows in a few languages and uC but no Linux experience)

I got a Raspi 3 and the 7in touch screen running jessie. Installed wxpython and successfully started a small script displaying a Speedmeter (wx.lib.agw.speedmeter) in Fullscreen.
The Raspi is set to autologin and boots into X

What I want to do is have the whole thing in my car (assuming some OBD interfacing maybe media related stuff via xbmc, openelec or the like, tempsensor,...)

This requires getting the .py executed in some way preferably by a touch (or "double touch") on the Desktop.
I normally do execute from the terminal using "sudo python Whatever.py"

I already tried creating a "pi.desktop" file which shows an Icon but after double clicking there is the circle next to the pointer and nothing happens (circle is gone after 10 sec or so).

My pi.desktop looks like

[Desktop Entry]
Name=MyFunnyApp
Comment=Does weird things
Icon=/usr/share/pixmaps/openbox.xpm
Exec=sudo python "/home/pi/MyStuff/Weird.py"
Type=Application

I did a chmod +x pi.desktop

Unfortunate everything to no avail.

Would appreciate any education/ideas/links

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Execute python from desktop

Fri Apr 15, 2016 4:23 pm

Alter the Exec= line to include the full path to the Python interpreter, as you have done with weird.py

You can find the path by entering which python at a shell (terminal) prompt.

[[Added later: I think @JimmyN's suggestion (below) wrt having a terminal open is more likely to be the underlying issue... ]]
Last edited by B.Goode on Fri Apr 15, 2016 8:00 pm, edited 1 time in total.

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Execute python from desktop

Fri Apr 15, 2016 7:23 pm

The .desktop files don't need to be executable, just readable. A 644 permission works fine.

Since you have the "busy" cursor that likely means it started up and is running in the background. I've noticed that with desktop shortcuts the program/script starts right up, but the "busy" indicator continues to spin for about 10~15 seconds. If you double click on a script on the desktop it will start up without that, but the same script when started from a shortcut will cause the cursor to churn for a bit after the script starts running.

But is likely that you don't have a terminal open, so there is nothing to see. Check to see if the script is actually running in the background.

Code: Select all

ps aux | grep Weird.py
Try adding

Code: Select all

Terminal=true
to the .desktop file so it will open in a terminal when you click on the shortcut.

zweiundvierzig
Posts: 3
Joined: Fri Apr 15, 2016 3:47 pm

Re: Execute python from desktop

Sun Apr 17, 2016 7:53 am

Thanks both, very helpful ideas that bring me forward.
I see the terminal popping up, then there is some text and then it closes.
Did try to encapsulate the whole script in a try/except and adding a sleep(10) to the except but that did not stop.
PS aux shows the script running.

There are a few steps for me to undertake now a to learn basic linux (e.g. ps) as well as continue my troubleshooting.

I will get back here as you were very helpful very quick ;)

Thanks for your help,
42

zweiundvierzig
Posts: 3
Joined: Fri Apr 15, 2016 3:47 pm

Re: Execute python from desktop

Sun Apr 17, 2016 4:39 pm

Thanks everyone, I was blunt enough to assume that a provided sample does actually work.
Nevertheless it didn't (http://trac.wxwidgets.org/ticket/17293) and after upgrading my speedmeter.py everything works out fine.

cheers, 42

Return to “Python”