Python is one of the core packages that comes by default with CentOS Linux. However, it is not updated at all on CentOS 6.x, the default version is 2.6.6, which is a little bit old for the current dev requirements when you are building a web app based on this language.
If you need to install Python 2.7 or 3.x versions on CentOS 6, there is one way to install this alternatives without breaking the default Python version, which is widely used by the OS and its tools like yum/dnf.
This may work on CentOS plain servers, but also on cPanel servers.
3 steps to Install Python 2.7 and Django on CentOS 6
1) Get latest Python 2.7.x version
Extract, configure, compile and install.
In the last step make sure you run: make altinstall, to avoid any conflicts with the default CentOS python version.
mkdir /root/temp && cd /root/temp wget http://python.org/ftp/python/2.7.10/Python-2.7.10.tgz tar -xvpzf Python-2.7.10.tgz ./configure cd Python-2.7.10 ./configure make make altinstall
At this point you should be able to execute python 2.7.x using this binary:
Now that we have Python 2.7 working, let’s get PIP to install some additional modules:
2) Install PIP
PIP is the right tool to manage and install python packages, make sure you run the installer calling the python2.7 binary.
cd /root/temp wget https://bootstrap.pypa.io/get-pip.py /usr/local/bin/python2.7 /root/temp/get-pip.py
3) Install Django 1.8
Django is one of the most popular Python frameworks. Let’s use PIP to install Django 1.8.x.
pip2.7 install Django==1.8.3
Need to Install additional Python modules?
Let’s use pip too, as easy as it looks:
pip2.7 install django-debug-toolbar pip2.7 install django-smart-selects pip2.7 install mysqlclient pip2.7 install Pillow pip2.7 install python-dateutil pip2.7 install PyYAML
Repeat the same procedure for all the python/django modules you need.
That’s all. At this point you should have two Python versions, the default from CentOS and the alternative we installed. Do you know other alternative methods to install Python 2.7 on CentOS?