Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to add a shebang to Python files

📅 2013-Jun-05 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ env, python, shebang ⬩ 📚 Archive

By adding a shebang to your Python source file and making it executable, you can run it directly at the shell.

The most straightforward shebang that can be added is a path to the Python executable. For example, on my computer this is:

#!/usr/bin/python

But the preferred method seems to be to use the env program:

#!/usr/bin/env python

By using env, you do not have to worry where the Python executable is located. env will just use whatever python it can find first in the PATH.

Tried with: Ubuntu 12.04 LTS


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email