Python script cannot run from .desktop launcher
5,139
This works for me :
First, my desktop file
[Desktop Entry]
Version=1.0
Name=My Application
Comment=My Application Comment :-)
Exec=/usr/local/script.py
Icon=/usr/local/script.py
Path=/usr/local
Terminal=false
Type=Application
Categories=Utility;Application;
Next, maks the script executable :
Make sure the first line of your file has #!/usr/bin/env python
Make it executable - chmod +x script.py
An alternative is to use the python command line in the desktop file
Exec=python /usr/local/script.py
Related videos on Youtube
Author by
Qubix
Updated on September 18, 2022Comments
-
Qubix over 1 year
I have a python script that works perfectly if I just run:
python3 script.py
If I make a
.desktop
shortcut, with the above command, the sidebar script is opened (the py file is a GUI) but then it closes and nothing happens.It is true that the
script.py
file takes about 10 seconds to load the GUI, but it does work perfectly, while the shortcut just shows a python script running on the sidebar, then closes.EDIT: I tried to launch the shortcut in the terminal:
gtk-launch script.desktop
which gives
gtk-launch: no such application script.desktop
-
damadam almost 6 yearsIssues with
.desktop
of script (python, shell ...) are the permissions; you have less permissions to run the script using a desktop shortcut than launching it with the terminal. That's due to permissions that the shortcut got -
Qubix almost 6 yearsunfortunately the permissions are not the issue.
-
-
Peter about 5 yearsI have this problem in 19.04 when trying to launch the latest version of wxGlade. It makes no difference whether I prefix the command with python3 or not. Both versions of the command work from the the command line. Binary executables start up just fine from the desktop.