ku1918
ku1918

Reputation: 67

how to make python script executable when click on the file

I am trying to make my python script executable without going through the terminal typing like

python test.py

I want to make it able to run when i click on the file.

How i going to do this in my fedora machine.

Upvotes: 3

Views: 14700

Answers (7)

supriyadi
supriyadi

Reputation: 1

I use raspibian os (Linux)

  1. Add #!/usr/bin/python as the first line of the file.py
  2. right click file >> open with >> chose customize >> custom command line >> type python3
  3. execute file with double click is working

Upvotes: 0

Eviner Santos
Eviner Santos

Reputation: 34

I know it can be too late, but i did have the same idea. (run python scripts in fedora) and found some trouble. My suggestion to you is to make a launcher with a .sh file, like this:

#!/bin/sh
gnome-terminal -x python yourscript.py

Give the permition to execute with chmod +x file.sh, them click and will run.

[^_~]

Upvotes: 0

ejntoo
ejntoo

Reputation: 11

It's Nautilus's fault. Open Nautilus (the file manager), go to Menu > Preferences. Select the "Behaviour" section. On the field titled "Executable text files", select the option "Execute executable text files when opened".

Upvotes: 1

Waterlink
Waterlink

Reputation: 2369

  1. Add #!/usr/bin/env python at the very beginning of file.
  2. Make chmod u+x filename.py
  3. Change your extension from .py to .sh, so your linux distro's UI will recognize it as shell script and try to execute.

Upvotes: 3

Burhan Khalid
Burhan Khalid

Reputation: 174632

  1. Add #!/bin/python as the very first line of your file. Or, if you don't know where your python executable is, type which python in a terminal; then copy the result of that and put it after the #!.

  2. Change the permissions of the file so that its executable chmod u+x test.py


i try but it still open back as gedit

  1. Right click on the file in your gnome file browser or desktop.
  2. Select Properties
  3. Go to Open with and choose Python. If you don't see python in the list, add the command. Just type python in the command to be added.

Upvotes: 5

DevC
DevC

Reputation: 7423

If you don't have any specific version requirement then using first line as #!/usr/bin/env python will be more efficient and give the execute permission chmod u+x test.py

Upvotes: 0

Andreas Mueller
Andreas Mueller

Reputation: 28768

Add #!/usr/bin/python as the first line of the file and set the permission to executable chmod 755 yourfile.

Upvotes: 0

Related Questions