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 ?

1 Answer 1


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.

  • yes but if you run a program that afterwards calls python bla bla than this will not work. And yes I agree for every new scripts this should be used Jan 29, 2013 at 0:16
  • 5
    Perhaps #!/usr/bin/env python2, since many environments will have python2, but not at /usr/bin
    – kojiro
    Jan 29, 2013 at 0:38
  • 1
    The PEP for python2/3 binaries is PEP 394
    – Wieland
    Jan 29, 2013 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .