ise7
Posts: 10
Joined: Mon Jul 16, 2018 8:46 am

Desktop Shortcut for Pi script; Nothing is working for me

Mon Jul 16, 2018 8:53 am

Seems like this would be ez but i just can't seem to figure it out. Used google and search and none of the solutions seem to be working for me.

I have a python script that I want to create a desktop short cut for.
The script is located on the USB stick @ /media/pi/SMT_DATA/SMT2.py
I want to use my python 3.6 install and berryconda located in /home/pi/berryconda3

In my script I have #!/usr/bin/env python at the top
I also used chmod +x SMT2.py

I created a desktop entry on desktop

This one gives me a invalid desktop entry

Code: Select all

[Desktop Entry]
Type=Application
Name=SMT Program
Exec=/media/pi/SMT_DATA/SMT2.py
Icon=/media/pi/SMT_DATA/files/SMT.ico
StartupNotify=true
This one I copied from another post just spins and nothing happens?

Code: Select all

[Desktop Entry]
Type=Application
Name=SMT Program
Exec=lxterminal /media/pi/SMT_DATA/SMT2.py
StartupNotify=true
Icon=/media/pi/SMT_DATA/files/SMT.ico
What am i doing wrong?? Why is it so hard to do something so simple????? Linux is making me tear my hair out

User avatar
topguy
Posts: 4611
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Desktop Shortcut for Pi script; Nothing is working for me

Mon Jul 16, 2018 12:05 pm

If you run this in a terminal opened on the desktop.

Code: Select all

/usr/bin/env python --version
Do you get correct Python version ?

klricks
Posts: 5663
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Desktop Shortcut for Pi script; Nothing is working for me

Mon Jul 16, 2018 12:51 pm

In your first desktop entry try:

Code: Select all

Exec=python /media/pi/SMT_DATA/SMT2.py
In the second desktop entry try:

Code: Select all

Exec=lxterminal -e python /media/pi/SMT_DATA/SMT2.py
Note if Python 3 then use python3 above.

Also note..... To test, run your script from the command line. In general if it does not work from the CL then it is not going to work as a Exec
Edit:
just noticed that you installed python 3.6 so use the complete path

Code: Select all

Exec=lxterminal -e /path/python /media/pi/SMT_DATA/SMT2.py
Again whatever works from CL.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ise7
Posts: 10
Joined: Mon Jul 16, 2018 8:46 am

Re: Desktop Shortcut for Pi script; Nothing is working for me

Tue Jul 17, 2018 10:09 am

Hey guys thanks for the help I did get it working with the complete path! But I just had some questions regarding what I'm actually doing

This was the working code finally, what does the -e do? Also what is the difference between Exec=lxterminal and leaving it out?

Code: Select all

Exec=lxterminal -e /home/pi/berryconda3/bin/python3.6 /media/pi/SMT_DATA/SMT2.py[code]
When I run the code below in terminal i get Python 3.6.1 does this mean It's part of my env?

Code: Select all

/usr/bin/env python --version


When the below code doesn't work is it because my env is misconfigured or should the first line in my script not be #!/usr/bin/env python?

Code: Select all

Exec=python /media/pi/SMT_DATA/SMT2.py


Also any advice on how to get the script to run automatically when the pi is turned on?

Again thanks for all the help guys! I spent all weekend trying to figure this out.

User avatar
topguy
Posts: 4611
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Desktop Shortcut for Pi script; Nothing is working for me

Tue Jul 17, 2018 11:49 am

"lxterminal" is the name of the terminal program.
"-e" tells lxterminal to run the following command instead of just giving you a shell.
When I run the code below in terminal i get Python 3.6.1 does this mean It's part of my env?
It means the first "python" found when using the $PATH variable in your environment variable is Python 3.6.1
Run these in a terminal.

Code: Select all

echo $PATH
which python
ls -l $(which python)
I have a standard setup on my Pi so it looks like this:

Code: Select all

[email protected]:~$ which python
/usr/bin/python
[email protected]:~$ which python2
/usr/bin/python2
[email protected]:~$ which python3
/usr/bin/python3
[email protected]:~$ ls -l $(which python)
lrwxrwxrwx 1 root root 9 Mar 28  2015 /usr/bin/python -> python2.7
[email protected]:~$ ls -l $(which python2)
lrwxrwxrwx 1 root root 9 Mar 28  2015 /usr/bin/python2 -> python2.7
[email protected]:~$ ls -l $(which python3)
lrwxrwxrwx 1 root root 9 Dec  6  2014 /usr/bin/python3 -> python3.4

klricks
Posts: 5663
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Desktop Shortcut for Pi script; Nothing is working for me

Tue Jul 17, 2018 12:50 pm

ise7 wrote:
Tue Jul 17, 2018 10:09 am
...
Also any advice on how to get the script to run automatically when the pi is turned on?
...
Edit autostart and add your command to the end of what's there:

Code: Select all

nano /home/pi/.config/lxsession/LXDE-pi/autostart

Code: Select all

@lxterminal -e /home/pi/berryconda3/bin/python3.6 /media/pi/SMT_DATA/SMT2.py
To test you can logout and back in... faster than rebooting.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ise7
Posts: 10
Joined: Mon Jul 16, 2018 8:46 am

Re: Desktop Shortcut for Pi script; Nothing is working for me

Wed Jul 18, 2018 10:54 am

Hey thanks again for the help.

Adding those lines to autostart allow my script to load automatically when i log off and login but not when opening the device fresh.

Is there something I'm missing to allow it to autoload with the power plugged in?

klricks
Posts: 5663
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Desktop Shortcut for Pi script; Nothing is working for me

Wed Jul 18, 2018 12:41 pm

ise7 wrote:
Wed Jul 18, 2018 10:54 am
Hey thanks again for the help.

Adding those lines to autostart allow my script to load automatically when i log off and login but not when opening the device fresh.

Is there something I'm missing to allow it to autoload with the power plugged in?
Make a bash script and add a sleep command. Then start the script from autostart:

Code: Select all

nano my_script

Code: Select all

#!/bin/bash
sleep 5   # adjust time as needed
lxterminal -e /home/pi/berryconda3/bin/python3.6 /media/pi/SMT_DATA/SMT2.py
autostart:

Code: Select all

@bash /home/pi/my_script
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

ise7
Posts: 10
Joined: Mon Jul 16, 2018 8:46 am

Re: Desktop Shortcut for Pi script; Nothing is working for me

Wed Jul 18, 2018 11:17 pm

it works great! Thanks so much for the help

Return to “Raspbian”

Who is online

Users browsing this forum: No registered users and 16 guests