Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Your Answer


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.