3

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.

1

7 Answers 7

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.
Sign up to request clarification or add additional context in comments.

Comments

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

4 Comments

everything still open back as a textfile.I did what as you said but it is still open with geedit
You can try change extension to .sh
still unable to do so.is it my fedora has a bug? all file are open with gedit.
When you clicking on file with right-click, do you see some option like "Execute" or similiar ?
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".

2 Comments

Where is there any mention of Nautilus?
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.
0

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

1 Comment

#!/usr/bin/env python is to be preferred for compatibility.
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

Comments

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.

[^_~]

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.