Bash – Correct handling of Python2 and Python3

bashpathpythonunix-philosophy

What is the correct way running scripts that depend on python2.x but on a system where python3.x is aliased with python.

The solution should take into account the following things :

  • Python2 should be used only for that bash run
  • every script that is run form subsequently should also use Python2
  • The change should be temporary

One solution is temporary making alias and setting the location for Python2 at the beginning of the full PATH.

What is the right (*nix) way to handle this ?

Best Answer

The correct way is to use #!/usr/bin/python2 as shbang line. More and more distributions support this now, and even upstream python development has adopted it.

Related Question