[Tutor] Linux Programs

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Thu, 3 May 2001 22:15:15 -0700 (PDT)


On Thu, 3 May 2001, Timothy M. Brauch wrote:
> 
> But, the problem comes after that.  I can't get my programs to run
> outside of Idle.  I know I have to add a line at the beginning of each
> python file, but I don't know what that line is.  When I wrote Python
> files for a class on the (Mandrake) Linux machines, the line was:
> 
> #!/usr/bin/python
> 
> This line doesn't work on my computer.  All I get is the file openned in
> a text editor.  I have Python installed in /usr/lib/python1.5/ because
> that is where it was installed when I installed Linux.  /usr/bin/python
> and /usr/bin/python1.5 both exist, but putting '#!/usr/bin/python' or
> '#!/usr/bin/python1.5' still opens the files in a text editor, even if I
> saved the file as 'test.py'
> 
> Can anyone help me?  I need to be able to write Python programs so I can
> start my assignment of creating the Processor Simulator.

One other thing you might need to do is make the file "executable" ---
that is, you need to flag it so that Linux knows that it's supposed to be
run as a program.  At the moment, Mandrake's file manager probably still
thinks that it should be treated as a text document.


If you know about the command line shell, try this:

   $ chmod +x test.py

which tells the system to flag the "eXecutable" bit on a file.  This
flagging, combined with the magic line "#!/usr/bin/python", should do the
trick.