I've created a simple python script and therefor have a .py file. I can run it from the terminal but if I double click it only opens up in gedit. I've read this question other places and tried the solutions, however none have worked. I'm running Ubuntu 13.04, I've selected the box to make the file executable. I've even installed a fresh instance of Ubuntu 13.10 on another computer and it does the same thing. What might I be missing here?
-
did you do sudo chmod +x file.py ??inye– inye2014-03-07 22:42:41 +00:00Commented Mar 7, 2014 at 22:42
-
Yes, just now I tried that too, still the same thing. It must be something simple I'm doing wrong.Alfred– Alfred2014-03-08 00:00:21 +00:00Commented Mar 8, 2014 at 0:00
-
you see stackoverflow.com/questions/1418553/… ??inye– inye2014-03-08 20:00:59 +00:00Commented Mar 8, 2014 at 20:00
-
or help.gnome.org/users/gnome-help/3.7/nautilus-behavior.html.en if you use nautilusinye– inye2014-03-08 20:02:57 +00:00Commented Mar 8, 2014 at 20:02
5 Answers
I had pretty much the same problem. I finally came across the solution at Ask Ubuntu. You have to change the nautilus file manager setting. Go to
Edit -> Preferences -> Behavior
and select the option as shown in the picture. Select Ask each time if you want to avoid unwanted execution of the script.

Comments
You have to give the file execution permission:
~ $ sudo chmod u+x your_file.py
You should also add this as the first line of the file to tell the system about the program it should use to execute your script:
#!/usr/bin/env python
This will search your environment (env) for the path of python. If you want it to execute in Python 3, replace python with python3.
Then your system should automatically ask you whether you want to run the program or to show the code.