Sometimes, if the answer is not very clear (I mean you cannot decide if yes or no), then it does not matter too much, and you can ignore the problem until the answer is clear.
The #!
only purpose is for launching the script. Django loads the sources on its own and uses them. It never needs to decide what interpreter should be used. This way, the #!
actually makes no sense here.
Generally, if it is a module and cannot be used as a script, there is no need for using the #!
. On the other hand, a module source often contains if __name__ == '__main__': ...
with at least some trivial testing of the functionality. Then the #!
makes sense again.
One good reason for using #!
is when you use both Python 2 and Python 3 scripts -- they must be interpreted by different versions of Python. This way, you have to remember what python
must be used when launching the script manually (without the #!
inside). If you have a mixture of such scripts, it is a good idea to use the #!
inside, make them executable, and launch them as executables (chmod ...).
When using MS-Windows, the #!
had no sense -- until recently. Python 3.3 introduces a Windows Python Launcher (py.exe and pyw.exe) that reads the #!
line, detects the installed versions of Python, and uses the correct or explicitly wanted version of Python. As the extension can be associated with a program, you can get similar behaviour in Windows as with execute flag in Unix-based systems.
#!/usr/bin/python
compare to the first option? I see this in quite a lot of example code. Edit: Maybe this is the answer.. stackoverflow.com/a/2429517/1156245 – geotheory/usr/bin/env python
is explicit, and means "use the environment's default python", allowing pip/user/OS/local admin/virtualenv to select one via$PATH
, while/usr/bin/python
forces the OS-selected python – MestreLion