When I use the shebang
#!/usr/bin/env python to run a script, how does the system know which
python to use? if I look for a
python bin path in the environment variables I find nothing.
env | grep -i python
The shebang expects a full path to the interpreter to use so the following syntax would be incorrect:
Setting a full path like this would work:
but would be non portable as python might be installed in /bin or /opt/python/bin or wherever location.
is a method allowing a portable way to specify to the OS a full path equivalent to the actual one where python is first located in the PATH.
The shebang line (from “sharp bang”, i.e.
on the first line, and when you execute the script, the kernel will in fact execute
Although this is not officially guaranteed, historic Unix systems provided
Right, so run:
Your $PATH is a list of directories. Unix will go through that list of directories, in order, until it finds "python".
You can see which directory it finds with the 'which' command: