Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First understand why shebang is needed -<br> Using a shebang lets the system know which command to use to run the script.</p> <p>What does that mean?<br> It means when you simply execute your script like this in the terminal - </p> <pre><code>$ ./script.py </code></pre> <p>"script.py" is given as an argument to the command you have mentioned in the commandline.</p> <p>So, if the shebang points to the python interpreter, the above command would be equivalent to this -</p> <pre><code>$ python script.py </code></pre> <p>So now you can understand the purpose of shebang - It just gives the path of the script interpreter. (in your case, the python interpreter).</p> <p>Note, that shebang is meaningless if you execute your script like this - </p> <pre><code>$ python script.py </code></pre> <p>(This is because you are calling the python executable and passing script.py as the first argument and it simply ignores the first line as it is a comment for it.)</p> <p>So, coming to your problem now - If you have two python installations and you want to execute your script using the non default python installation, what you do is either -<br> 1. simply execute as <code>$ /opt/bin/python script.py</code> and ignore the shebang.<br> OR<br> 2. Change <code>script.py</code>'s shebang you can and then you can execute as <code>./script.py</code></p> <p>I would choose the 1st option if I had to run <code>script.py</code> just once, and the 2nd one if I had to execute it many times (so I don't waste time writing <code>/opt/bin/python</code> every time)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload