2

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.

ku1918
  • 57
  • 1
  • 2
  • 7
  • 1
    possible duplicate of [What do I use on linux to make a python program executable](http://stackoverflow.com/questions/304883/what-do-i-use-on-linux-to-make-a-python-program-executable) – zero323 Oct 22 '13 at 05:57

7 Answers7

5
  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.
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
2
  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.
Waterlink
  • 2,239
  • 1
  • 17
  • 27
1

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".

ejntoo
  • 11
  • 1
  • Where is there any mention of Nautilus? – EWit Apr 06 '14 at 19:08
  • He wanted to open the program double clicking on its icon, so he was using Nautilus. It was a wrong setting that didn't let him run executable files. – ejntoo Aug 14 '14 at 13:56
0

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

Andreas Mueller
  • 27,470
  • 8
  • 62
  • 74
0

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

DevC
  • 7,055
  • 9
  • 39
  • 58
0

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.

[^_~]
Eviner Santos
  • 34
  • 1
  • 2
0

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