running python 2 vs 3

Zachary Ware zachary.ware+pylist at
Thu Mar 20 17:14:54 CET 2014

On Thu, Mar 20, 2014 at 11:00 AM, notbob <notbob at> wrote:
> Ahhh! a shabang I understand.  So, I guess the only way, short
> of looking at the actual file, is to include the version in the
> filename.  Can I safely assume I can run all 2.7 files w/o a shebang
> (which I have not, so far, and was wondering how I got away with that)
> and only include a py3 shebang in the py3 files, yes/no?

If I understand your question: you're probably better off putting a
shebang line in all of the files that you intend to run directly.  Use
"/usr/bin/env python2" for your Python 2 scripts, "/usr/bin/env
python3" for your Python 3 scripts, and "/usr/bin/env python" for
scripts that can run under either interpreter.  You can also be more
version-specific if you need to; use "python2.7", "python3.3", etc. as
necessary.  That way, you can invoke the script directly and the right
interpreter will run it.  If you're specifying the interpreter in your
command (by calling "python <scriptname>.py", etc), the shebang won't
mean anything anyway.


More information about the Python-list mailing list