Newbie: "compiling" scrips (?)

Steve Holden sholden at holdenweb.com
Wed Jun 25 07:47:53 EDT 2003


"Troels Therkelsen" <t_therkelsen at hotmail.com> wrote in message
news:slrnbfj02u.dk.t_therkelsen at abattoir.2-10.org...
[how to "compile" Python]
>
> I don't know if this answers your question, but in order for a Python
script
> (or any script, really) to be executable under Linux (and all UNIX-like
> systems), you need to do two things:
>
>    1) Make sure that the file has the executable bit set.  This can be
done
>       with the chmod command, for example 'chmod +x my_file.py'.  Be sure
to
>       read the man page for chmod, if you aren't already familiar with
this
>       command.
>
>    2) At the very first line of your script file you must have a so-called
>       shebang line.  This line tells your shell how to execute the file.
The
>       Python tutorial recommends this shebang:
>
>           #! /usr/bin/env python
>
>       (No spaces before the # and the newline *must* be '\n'.  If you use
>       '\r\n' it won't work and the error message isn't very helpful)
>
> Alternatively, if you don't wish to do all this, you can also execute your
> script by typing 'python my_file.py'.  Regardless of which approach you
take,
> however, python must be in your $PATH for either of them to work.  If
python
> has been properly installed on your system, it will be.
>
Of course, if the shebang line explicitly names the Python executable then
there is no need for it to be on the user's PATH. On Red Hat 8.0, for
example:

[sholden at munger sholden]$ cat test.py
#!/usr/bin/python
print "So, Python need not be on the path!"
[sholden at munger sholden]$ export PATH=`pwd` # don't try this at home ...
[sholden at munger sholden]$ echo $PATH
/home/sholden
[sholden at munger sholden]$ test.py
So, Python need not be on the path!

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list