Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks

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

migrated from stackoverflow.com Jan 26 '13 at 19:26

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

2 Answers

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
add comment

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

/usr/local/bin/python2.7

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
add comment

Your Answer

 
discard

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