Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasises readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all the key platforms and can be freely distributed.
By default on CentOS or any other popular Linux distribution Python, 2.6 version is installed.
You can check the current version with the following command:
~]# python -V
Python 2.6.6
Install optional Python version from IUS Community repository
To install Python 2.7 on the server, please do the following:
Log in as root (superuser) and push:
cd /root ; wget -c https://centos6.iuscommunity.org/ius-release.rpm ; rpm -ivh ius-release.rpm
On CentOS 7:
cd /root ; wget -c https://centos7.iuscommunity.org/ius-release.rpm ; rpm -ivh ius-release.rpm
After IUS Community repositories are successfully installed (https://ius.io/GettingStarted/) you need to run the following commands:
yum -y install python27 python27-devel python27-pip python27-setuptools python27-virtualenv --enablerepo=ius
After packages get successfully installed, you can test if python2.7 and pip are working as expected, for example:
[root@second ~]# python2.7 -V
Python 2.7.13
[root@second ~]# pip2.7
Usage:
pip <command> [options]
[root@second ~]# virtualenv-2.7
You must provide a DEST_DIR
Usage: virtualenv-2.7 [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
You may create an alias within the username by adjusting .bashrc file for python and virtualenv with the optional Python 2.7 version, for example:
alias python='/usr/bin/python2.7'
alias virtuelenv='/usr/bin/virtualenv-2.7'
Repeat procedure In case you wish optional Python3+ version installed.
Related articles
https://ius.io/GettingStarted/
https://community.letsencrypt.org/t/redhat-centos-6-x-users-need-python-2-7/2190
Install optional Python version from Software Collections (SCL) Repository
Software Collections give you the power to build, install, and use multiple versions of software on the same system, without affecting system-wide installed packages.
To install Python 2.7 on CentOS server, please do the following:
Install The Software Collections ( SCL ) Repository:
yum install centos-release-scl
Install python27 from SCL repository:
yum install python27 -y
Enable python27 with the following command:
scl enable python27 bash
Test active Python version:
python -V
The System should return "Python 2.7.X" Where X is the latest version of python in this branch.
Related article:
https://www.softwarecollections.org/en/
Install optional Python version using Anaconda
With Anaconda you can run multiple versions of Python in isolated environments, so choose the download with the Python version that you use more often, as that will be your default Python version.
If you don't have the time or disk space for the entire distribution, try Miniconda (http://conda.pydata.org/miniconda.html) which contains only conda and Python. Then install just the individual packages you want through the conda command.
1) Linux installer at https://www.continuum.io/downloads
2) Run the provided bash command from above to start the installer:
bash Anaconda3-4.4.0-Linux-x86_64.sh
For Python 2.7 version:
bash Anaconda2-4.4.0-Linux-x86_64.sh
3) Agree to the license agreement
4) Set the install location on /home somewhere, like 5) /home/anaconda3
6) Add to bashrc when prompted.
7) Exit current user and relog or source bashrc
8) run "python -V" and you should see 3.6.1 (latest version)
Anaconda is BSD licensed which gives you permission to use Anaconda commercially and for redistribution.
Related article:
https://www.continuum.io/downloads
These are three known methods I've selected if you need optional Python versions on your server installed. Of course, you can compile, but who needs that when you can use different repositories to complete the task.