It seems to me like the files run the same without that line.
|
That is called the shebang line. As the Wikipedia entry explains:
See also the Unix FAQ entry. Even on Windows, where the shebang line does not determine the interpreter to be run, you can pass options to the interpreter by specifying them on the shebang line. I find it useful to keep a generic shebang line in one-off scripts (such as the ones I write when answering questions on SO), so I can quickly test them on both Windows and ArchLinux. The env utility allows you to invoke a command on the path:
| |||||||||
|
If you have several versions of Python installed, In Unix, an executable file that's meant to be interpreted must indicate what interpreter to use by having a If you're talking about other platforms, of course, this rule does not apply (but that "shebang line" does no harm, and will help if you ever copy that script to a platform with a Unix base, such as Linux, Mac, etc). | |||||||||||||||||||||
|
This is a shell convention that tells the shell which program can execute the script. #!/usr/bin/env python resolves to a path to the Python binary. | |||
|
Technically, in Python, this is just a comment line. This line is only used if you run the py script from the shell (from the command line). This is know as the "Shebang!" and is used in various situations, not just with Python scripts | |||||
|
Expanding a bit on the other answers, here's a little example of how your command line scripts can get into trouble by incautious use of
The json module doesn't exist in Python 2.5. One way to guard against that kind of problem is to use the versioned python command names that are typically installed with most Pythons:
If you just need to distinguish between Python 2.x and Python 3.x, recent releases of Python 3 also provide a
| |||||||||
|
The main reason to do this is to make the script portable across operating system environments. For example under mingw, python scripts use :
and under GNU/Linux distribution it is either:
or
and under the best commercial Unix sw/hw system of all (OS/X), it is:
or on FreeBSD:
However all these differences can make the script portable across all by using:
| |||||
|
It's recommended way, proposed in documentation:
from http://docs.python.org/py3k/tutorial/interpreter.html#executable-python-scripts | |||
|
In order to run the python script, we need to tell the shell three things:
The shebang The
| |||
|
You can try this issue using virtualenv Here is test.py
Create virtual environments
activate each environment then check the differences
| |||
|