[Tutor] starting python within script

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 29 Aug 2000 17:38:31 +0200

On Tue, Aug 29, 2000 at 11:15:11AM -0400, Tim Condit wrote:
> I'm curious about the two ways I see python started from inside scripts.
> These are the locations on my desktop computer at work: 
> #!/usr/bin/env python
> #!/usr/local/bin/python
> One of these creates a .pyc byte compiled file. The other doesn't. What is
> the advantage of one over the other?

/usr/local/bin/ is a hardcoded path, it may not work everywhere; sometimes
Python is in /usr/bin, sometimes in /usr/local/bin, then in /opt/python,

"env" is a program that starts another program, it looks "python" up in
PATH and starts it. So that env line finds Python wherever it is, if it's
in your PATH.

So "env" works on more computers, but it can't be used if Python isn't in
the path (like on some web servers). Env is always in /usr/bin/env.

I think the rule is "use /usr/bin/env python, if you can."

But the thing about creating .pyc files is weird. When I try it, neither
produces a .pyc files. Those should never be created when the Python file
is run from the command line, but only when the script is imported from
another script (I don't know why that is). Are you sure that is what

Remco Gerlich,  scarblac@pino.selwerd.nl