Centos 6.5 is shipped with Python version 2.6. And for some projects and/or applications you may need to use version 2.7. First thing which comes to mind is to compile it from sources. But obviously it’s not the best way. It would create more problem in future, besides it’s quite easy to get the whole system broken. So there should be a better way. And there is: pyenv. Pyenv is a set of tools for Python versions management. You might be familiar with rbenv, similar thing for Ruby versions management. Installation of pyenv is very trivial using pyenv installer:
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
Once it’s done, you can install Python 2.7. Let’s find the latest version of branch 2.7:
[user@pybox ~]$ pyenv install -l | grep 2.7 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7-dev ironpython-2.7.4 jython-2.7-beta1 jython-2.7-beta2 jython-2.7-beta3 stackless-2.7.2 stackless-2.7.3 stackless-2.7.4 stackless-2.7.5 stackless-2.7.6 stackless-2.7-dev [user@pybox ~]$
Ok, so it’s 2.7.8. Before proceeding we also need the following development packages:
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel mysql-devel
Now we are to ready to install version 2.7.8:
pyenv install 2.7.8
When the compilation process is over, check:
[user@pybox ~]$ python -V Python 2.6.6 [user@pybox ~]$
Still 2.6.6. This is because our pyenv knows nothing about about our just installed Python. Let’s mark that we need version 2.7.8:
[user@pybox ~]$ pyenv local 2.7.8 [user@pybox ~]$ python -V Python 2.7.8 [user@pybox ~]
Here is what was changed:
[user@pybox ~]$ cat .python-version 2.7.8 [user@pybox ~]$
Now it’s installed and ready to use.