Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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