search by tags

for the user

adventures into the land of the command line

upgrading python 2.6 to 2.7 on centos\rhel 6

something i dread because i know that you can break everything if you mess it up, but i found two awesome writeups here and here

centos and rhel are more enterprisey distributions of linux and therefore focus on stability over bleeding edge, which is why you’ll usually find python 2.6.6 installed out of the box

there’s a bunch of system critical utilities which depend on python, such as yum, and so if you mess up the upgrade, you can break all of these important utilities

for the upgrade to work, we have to install a new python version into a non-standard location, so that there will be two python versions living side by side. so you might call this an install, rather than an upgrade

just three things before we start

unicode

enable UTF-32 in Python 2.7 by adding –enable-unicode=ucs4

shared library

compile python as a shared library by adding this to the end of the configure command: LDFLAGS=“-Wl,-rpath /usr/local/lib”

altinstall

use make altinstall when you install your custom version of python. if you use the normal make install you will end up with two different versions of python in the filesystem both named python, which is gonna be a real d*ck punch for you

so… let’s dew it. first of all, be root (or sudo every command)

$ sudo su -

install the development tools and the extra libs the python interpreter needs

$ yum groupinstall "Development tools"
$ yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

download, compile and install python

$ wget http://python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
$ tar xf Python-2.7.11.tar.xz
$ cd Python-2.7.11
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall

your newly installed python interpreter will be available as /usr/local/bin/python2.7. the system version of python 2.6.6 will continue to be available as /usr/bin/python, /usr/bin/python2 and /usr/bin/python2.6

[[email protected] ~]# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

[[email protected] ~]# python2.6
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

[[email protected] ~]# python2
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

[[email protected] ~]# python2.7
Python 2.7.11 (default, Mar  1 2016, 16:55:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

next install pip for python2.7

$ wget http://peak.telecommunity.com/dist/ez_setup.py
$ python2.7 ez_setup.py
$ easy_install-2.7 pip

all the packages you install using pip2.7 will run on python2.7 and pip2.6 packages will run on the system python 2.6.6 version. the pip binary will also start magically using pip2.7

[[email protected] ~]# pip2.6 list
distribute (0.6.10)
ethtool (0.6)
Flask (0.10.1)
gunicorn (19.3.0)
.
.
.


[[email protected] ~]# pip2.7 list
pip (8.0.3)
setuptools (20.2.2)

[[email protected] ~]# pip list
pip (8.0.3)
setuptools (20.2.2)

at this point, you might want to install virtualenv, but i’m a massive fan of vagrant, so i don’t use it. this is where i’ll stop. i also recommend reading the other articles for a more in depth and detailed explanation of whats going on here and why.