How do I create a desktop entry to launch a Python script?

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.


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;