How do I run a .py with double click?

Hi all.
Sorry the dumb question but i dont find the answer.
I have a program .py that of course i can run from a terminal like “python” but i dont want to go to a terminal, go to the “directory”, etc.
How i can make these?
Again, sorry…

If you want an icon on the desktop to double click to run, create a .desktop file.

I’m using XFCE. What I would do:

  1. Right click the desktop
  2. Select Create Launcher
  3. Complete the dialog
    For the “Command” line, click the button on the right to open the File Dialog so the program can be easily selected. Click “Run in Terminal” if required.

Now a new .desktop file is on the user’s desktop. You can right click the desktop launcher and select Properties or double click to run it. The actual file resides in $HOME/Desktop. .desktop files are an XDG standard so all desktops (GNOME, XFCE, KDE…) implement it. The “how” varies :slight_smile: but the concepts are the same, mostly.

If I needed the launcher in the menu (in my case since I use XFCE, it is the Whisker Menu), I would:

  1. Right click the menu
  2. Select Edit Applications
  3. Position myself in the menu tree where I wanted the new launcher. There are up and down arrows so I could reposition the launcher someplace else in the menu tree later.
  4. Click the “+” in the top menu to add a new launcher.
  5. Complete the dialog
  6. Test launcher
  7. Save the launcher

The actual .desktop file will reside in $HOME/.local/share/applications. You can view or edit the file, but using the tools provided make it a little easier to get started.



To add a little more info that may be helpful:

The Exec line in the desktop file should be:

Exec=python /path/to/

or if it’s an installed Python module:

Exec=python -m

Python scripts with #!/usr/bin/python can be run directly if it is marked as executable just as you would any shell script.

This makes it a piece of cake to create a launcher which can be used in the menu system or from the desktop - place the launcher in ~/.local/share/applications - and it will appear in your menu system

[Desktop Entry]
Name=My Python script
Comment=Your Comment for your Python script

Thanks to all.
Is working perfect!!!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.