Newbie: "compiling" scrips (?)
t_therkelsen at hotmail.com
Wed Jun 25 12:58:39 CEST 2003
In article <bdbrv2$9un$02$1 at news.t-online.com>, Thomas Weber wrote:
> I've just started to play around with python, I like the syntax quite
> a lot...
> But I have some problems to execute my scripts (in Linux, bash) that I
> wrote in an editor.
> Is there a way to compile the scripts into binary form like
> like in C: 'gcc source.c -o binary'
> Sorry, if this was a silly question...
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
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.
More information about the Python-list