Ubuntu – Stop .py opening in gedit

geditpython

I have been trying to get a .py file to open in the interpreter instead of in gedit and feel like i'm banging my head off a wall.

I have selected "Allow executing file as program" in Permission (it was already on to begin with). I have also ensured that "#!/usr/bin/python" is at the top of the file.

I have also chmod +x "script.py"

I am unsure what else to try, everything I have been reading has suggested this should work. But it still open's in gedit everytime the only way I can get this file to run is via terminal using either ./script.py or python script.py commands.

I am mostly a windows user and only tend to use Linux for testing purposes so please bear with me in your responses as I am not an expert on this by any means.

Thanks for any advice you can give.

Will

Best Answer

Its just a setting in the file browser Nautilus. Go to Edit > Preferences > Behaviour

enter image description here

Choose Run executable... to run an application on opening. To avoid running an application unwantedly it is however better to choose Ask each time.