Execute Your Python Scripts With a Shebang - Real Python
Briefly

The shebang line (#!) in shell scripts indicates which interpreter should execute the file, crucial for running scripts on Unix-like systems. In Python files, adding a shebang enables users to execute scripts directly without prepending 'python'. It’s important to include shebangs in scripts designed for direct execution while omitting them in modules that are meant for import. Best practices recommend using '/usr/bin/env' within shebangs for enhanced portability, and users should note that shebangs won't work on Windows without special compatibility layers such as WSL.
A shebang line at the top of your Python file tells the shell how to execute the script, making it possible to run scripts directly.
Including a shebang is essential when a script is meant for direct execution, but it should be excluded in Python modules meant solely for import.
Best practices suggest using '/usr/bin/env' in shebang lines for better portability across different environments, ensuring the script runs correctly.
It's important to be aware that shebangs can be ignored on Windows systems unless you utilize compatibility layers like Windows Subsystem for Linux.
Read at Realpython
[
|
]