Suppose you write a Python shell script. It will probably start with something like this:
#!/usr/bin/python
The problem is, if you often work with virtualenv this call is just plain wrong. You actually would like this script to call virtualenv’s python binary, if it is in this environment and /usr/bin/python/ otherwise. Just like your shell would decide, when you write python as a shell command.
How would you write your #! line to fulfil this requirement?
Use
#!/usr/bin/env pythoninstead.The
envcommand looks up binaries in the currentPATH; activating your virtual environment adds your virtualenvbin/directory to the path andenvwill find your python binary there instead of the global python.