adrive
adrive

Reputation: 81

Does shebang overwrite the python interpreter path

I’m wondering if shebang is specified in the python script, does it overwrite the caller?

For example, let’s say I have a test.py,

#!/usr/bin/python3
print(“hello world”)

And then I call it this way: /usr/bin/python2 test.py

Which python version will call the hello world print fiction?

Upvotes: 0

Views: 810

Answers (1)

Marcin Orlowski
Marcin Orlowski

Reputation: 75636

No. It is only used if you make your python file executable and run directly

./test.py

As it is being read and used by the shell attempting to run that file. By doing

/usr/bin/python2 test.py

you in fact run /usr/bin/python2 interpreter, which is given test.py as argument. And python interpreter ignores shebang as this is just python comment line syntax.

Upvotes: 4

Related Questions