7

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 ?

7

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.

3
  • 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 – Mite Mitreski Jan 29 '13 at 0:16
  • 5
    Perhaps #!/usr/bin/env python2, since many environments will have python2, but not at /usr/bin – kojiro Jan 29 '13 at 0:38
  • 1
    The PEP for python2/3 binaries is PEP 394 – Wieland Jan 29 '13 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.