2

I made my little Python app, but I can't launch the app using the desktop entry I created:

[Desktop Entry]
Name=MyApp
Version=0.1
Exec=/usr/share/MyApp/MyApp.py
Icon=/usr/share/MyApp/img/MyApp.png
Comment=Description......
Type=Application
Terminal=false
StartupNotify=false
Categories=Video;GTK;GNOME

The /usr/share/MyApp folder I made as root and the MyApp.py has executable properties.

Every time I double Click the MyApp.desktop the MyApp.py launch, display a systray icon, but it closes and make Ubuntu display a error message.

If I run the MyApp.py from terminal or double click on the .py file it runs normally, no crashes.

14

May I offer a few notes and improvements over the accepted answer?

  • Manually installing software to /usr/share is strongly discouraged!!! That tree should be reserved for software installed by your package manager (Ubuntu Software Center, apt, etc). There is usr/local/share for that. Or, if you don't want to use sudo, you may install for your user only at ~/.local/share. See https://askubuntu.com/a/135679/11015 for more information about software install directories.

  • If you want to execute a .desktop file by double-clicking on it, in Nautilus or your Desktop, just make the .desktop file executable! Note that this is not required if you copy it to /usr/share/applications and launch it via Dash/Menu. Or, better: copy to ~/.local/share/applications or at least /usr/local/share/applications, as suggested above.

  • Icon=/usr/share/MyApp/MyApp.py makes no sense: a .py file is not a valid image, so it cannot be used as an icon. If you want to use the default python icon, use /usr/share/pixmaps/python.xpm

  • The main difference between your .desktop file and the accepted answer is the Path=/usr/share/MyApp/ statement. If that made your app work, it means your software requires the current directory to be the application directory. And that is a bad thing: your software should be able to run fine and find its data files regardless of current directory. (hint: use python's __file__)

  • If your application is a GUI (ie, it has a window), then add StartupNotify=true. It will help the launcher identify its window when it is running.

3

Try following text in your .desktop file.

[Desktop Entry]
Version=1.0
Name=ProgramName
Comment=This is my comment
Exec=/usr/share/MyApp/MyApp.py
Icon=/usr/share/MyApp/MyApp.py
Path=/usr/share/MyApp/
Terminal=false
Type=Application
Categories=Utility;Application;
2
  • I got an untrusted application launcher error? May 25 '14 at 8:38
  • 2
    I had to explicitly add 'python' to the Exec config, i.e: Exec=python /usr/share/MyApp/MyApp.py
    – Keith
    Mar 3 '15 at 21:59
0

I think you should move your Python file to /usr/local/bin or /bin and remove the .py at the end and add #!/bin/python3 to first line of your python file then copy you icon to /usr/share/pixmaps and add this in the .desktop file

Exec=<your file name which is in bin>
Icon=<your logo name without .png or xpm at back>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.