What does #!/usr/bin/env python mean?

· by

You've probably already seen one of the following lines:

#!/bin/sh
#!/usr/bin/env python
#!/usr/bin/env python3
#!/usr/bin/env python
#!/usr/bin/perl
#!/usr/bin/php
#!/usr/bin/ruby

This is a shebang. It's a directive for your command line interpreter how it should execute a script.

For example, you have a file with this content:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

print(sys.version_info)

Now you can execute it via python3 yourFile.py. But alternatively, you can make it executable and simply type ./yourFile.py

By the way, you should use #!/usr/bin/env python for some reasons.