CentOS 5 Python – How To Force Specific Version

centospythonversion

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

Best Answer

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

Related Question