How to run .py script with left click of mouse? no need to point terminal to it

" Python files (.py ) aren't directly executable by default on most operating systems, even with chmod +x . They require an interpreter, usually the python or python3 command, to run the Python code within them."

So how can this be fixed?

I got a .py program/tool i need to be able to run with a sane & simple left click, I dont want to have to open up terminal, then type python3, then drag the python script into the terminal.

-Thanks!

u can create launcher on desktop and put the command in it: python3 YourScript.py, then u will be able to simple left click on it.
image

1 Like

Thanks! I took note of your advice. However I have python scripts that are in multiple folders and need to stay there, and I need to left click the .py file themselves and run them that way. A simple left click. :slight_smile:

it's depend on your file manager, i'm using zorin lite which the default file manager is thunar, i can make custom action in it which will appear in the context-menu when i select the python file or by using keyboard-shortcut, in other file mangers u can fix the custom action in the tool-bar, and in other file mangers like nautilus u can find extension may do that.
Peek 2024-04-14 03-22
[custom action i created it in thunar]

I've created a bash script that supposedly can launch a python script. Which would still mean all if had to do is one or two left clicks on the .sh script to launch the python script.

But the bash script is not working, perhaps one of you could take a look at it, I also made sure to chmod +x everything. The python script is located where two txt files it needs to do its job are.

#!/bin/bash

# Path to Python 3 interpreter (assuming /usr/bin/python3)
python_path=/usr/bin/python3

# Path to your Python script
script_path=/home/user/scriptPY.py

# Run the script directly
$python_path "$script_path"



Just use a header that point to python instead of bash ???
On my system first line has to be : ```
#!/usr/bin/python3

1 Like

Looks like I solved it. I'll leave this open & unsolved in case anyone has any better ideas that dont require involving sh script just to launch a py script. As its a bit redundant, inelegent.
I had to create an sh script to open the py script.

I've tried many sh scripts and approaches and this is the only one that worked, thanks for Gemini A.I. for helping me also, you gotta insert the file path to the py script in this:

#!/bin/bash

gnome-terminal --working-directory="(file path to the py script)" -e "python3 scriptPY.py" # Replace gnome-terminal with your terminal emulator (e.g., konsole, terminator)

read -p "Press Enter to close the original terminal..."
1 Like