Centos 6/RHEL install/compile Python3.3


You might want to use Python3.3 on your Centos 6 box and it doesn't ship as standard so needs to be compiled from source.

Fortunately, this is easy to do if you have Centos 6 set up properly as in the Centos 6 minimal tutorial. It is important that you do not remove python 2.6 as it is needed by many system files.

You will need some dependencies to enable the compilation and for python to function correctly.

$ sudo yum -y install wget gcc gcc-c++ autoconf automake make zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

$ wget http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2

Download the Gzip source file to your home directory

$ cd /tmp

$ sudo tar xvf /home/<user_name>/Python-3.3.0.tar.bz2

$ cd Python-3.3.0/

$ ./configure --prefix=/usr/local

$ sudo su

# make && make install

# cd

# rm -rf /tmp/Python-3.3.0/

Run it with

$ python3.3 

[anton@Centos ~]$ python3.3
Python 3.3.0 (default, Oct  5 2012, 19:37:37) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Just 'python' will invoke the 2.6 version as below


[anton@Centos ~]$ python
Python 2.6.6 (r266:84292, Sep 11 2012, 08:28:27) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

3.3 was installed on Oct 5th whereas 2.6 was part of the actual system installation when I built the computer in September, so you can run both.

Running three versions

You can also install Python 2.7.3 for example along with Python 3.3 above AND still keep the system version 2.6. Just repeat the process above but download the 2.7.3 version. You must change the line 'make install' to 'make altinstall' on both the 2.7 and the 3.3 installations to avoid naming conflicts.

Virtualenv provides a way of managing multiple Python installations whilst keeping headaches to a minimum.







Labels: , ,