Executing Python scripts with a shebang

· Thomas Taylor

The shebang line informs the operating system’s shell where to find the interpreter. The program loader will execute the specified interpreter with the same arguments that were initially passed.

Add a shebang (#!) to a Python script

How to add a shebang (#!) to a Python 3 file:

1#!/usr/bin/env python3
3print("hello world")

In addition to the normal execution by calling the interpreter directly:

1python3 ./

the file can be called like this:


Note: The executable may not have executable permissions by the user. To enable for this, simply run:

1chmod +x ./


Reply to this post by email ↪