Answer the question
In order to leave comments, you need to log in
How does shebang and python interpreter work?
All the best!
Please explain one very stupid, but haunting me "trick".
When creating any project for Python, it is considered good practice to create a virtual environment for it. $ python3 -m venv env
By activating the environment, the Python interpreter "moves" to the env folder, which can be easily seen
$ which python3
users/username/project/env/bin/python3
#!/env/bin/python
print('Hello World!')
#!users/username/project/env/bin/python3
print('Hello World!')
#! ~/env/bin/python3
print('Hello World!')
Answer the question
In order to leave comments, you need to log in
/usr/bin/env is the command that will find the correct binary. Because not in all cases, you have python in /usr/bin, not in all cases you have bash in /usr/bin
It's just more stability for scripts that can run on embedded linux, cygwin windows and other environments
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question