Super User is a question and answer site for computer enthusiasts and power users. 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

I have a python program that I'm trying to run, my fresh install of CentOS came with 2.4.3 of Python, but I just manually installed 2.7. My install is located at /usr/local/bin/python2.7, so its all there, but when I do

python -V

it comes back with 2.4.3. How would I force 2.7 (the latest) to be the main and only python as my program requires 2.6 or higher?


share|improve this question

migrated from Jan 26 '13 at 19:26

This question came from our site for professional and enthusiast programmers.

This might be more of a CentOS/Linux administration question than a programming one. You need the /usr/bin/python symlink to point to python2.7, or you need PATH to have such a symlink before the 2.4 one. You can either do that manually (sitewide or in your .bashrc or similar configuration file) or see if there's a version selecting utility on CentOS. (Similar to python_select on MacPorts.) – millimoose Jan 26 '13 at 15:39
@millimoose: it is a bad idea to change /usr/bin/python. Applications that do not expect this might break. – J.F. Sebastian Jan 26 '13 at 18:19
@J.F.Sebastian Yeah, I guess a better solution would be using virtualenv instead of relying on the OS environment to be set up right. – millimoose Jan 26 '13 at 19:02

To run your script using python2.7, you could change the shebang line in your script:

#!/usr/bin/env python2.7

Make sure python2.7 is in your PATH in this case.

To point other tools such as easy_install, pip to python2.7, you could use virtualenv. Create virtualenv for python2.7 and activate it in .bash_profile to make it default. See this answer about easy way to install virtualenv, easy_install, pip

share|improve this answer

Turns out your default python executable is 2.4.3, you need to either directly reference the 2.7 like so


or by replacing your python link to point to the new interpreter.

To check your running the right interpreter in your scripts you can do something like this;

assert platform.python_version_tuple()[:2] == ('2', '7')

Is a pretty common idonim

If you want to accept any version above 2.7 then do this

major, minor, _ = platform.python_version_tuple()
assert (int(major) >= 2) or ((int(major) == 2) and (int(major) >=7))
share|improve this answer

You must log in to answer this question.