Running a Python file

Cameron Hutchison lists at
Wed Jul 7 01:13:20 UTC 2010

Jim Byrnes <jf_byrnes at> writes:

>I have been teaching myself Python.  Running some of my programs and 
>others examples I noticed that some I could run by double-clicking them 
>and others I could not.  Looking at the file permissions I saw that they 
>were different.  Then I noticed that all the ones I could not run were 
>ones I gone into Properties-->Permissions and check execute as a 
>program.  Once I unchecked it they worked.

>This seems backwards to me.  Could someone tell me why this works this way?

If your python program is executable, it must have a first line of
something line this:

or sometimes

#!/usr/bin/env python

If you don't have this line, the kernel will not be able to execute it.
For more info on this first line, see:

If you turn off execute permission, I assume that the file manager
recognises that the file is a python program (with the .py extension)
and runs the python interpreter for you (from the command line, this
would look like: "python"). Without the file manager doing
something like this, the program would not be executable. It is likely
the same logic used when you double-click an document
(for example). is launched with the double-clicked file
as an argument.

More information about the ubuntu-users mailing list