Today, I was trying to install an application on my CentOS 7.4 system which required Python >= 2.7.10, but there are Python 2.7.5 installed, which we can’t remove as other applications depend on it. This tutorial will help you to install Python 2.7.14 without removing older versions.
Step 1 – Install GCC
Firstly make sure that you have GCC package installed on your system. Use the following command to install GCC if you don’t have it installed.
yum install gcc openssl-devel bzip2-devel
Step 2 – Download Python 2.7
Download Python using following command from python official site. You can also download the latest version in place of specified below.
cd /usr/src wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
Step 3 – Extract Archive and Compile
Use below set of commands to extract Python source code and compile it into your system using altinstall.
tar xzf Python-2.7.14.tgz cd Python-2.7.14 ./configure --enable-optimizations make altinstall
Step 4 – Check Python Version
Check the latest version installed of python using below command. During this installation, the latest Python binary was installed on path /usr/local/bin/python2.7. The existing binary was located under /usr/bin.
/usr/local/bin/python2.7 -V Python 2.7.14
Step 5 – Install PIP
PIP is a useful utility to install and manage Python modules. Let’s install the PIP for the installed Python version.
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python2.7 get-pip.py

python2.7 is not a valid command
/usr/local/bin/python2.7 –version ,This path need to be added to PATH
/usr/local/bin/python2.7 –version
what is the latest python version which supports RHEL 6.8 ?
I am getting error in the last command python2.7 get-pip.py
The following is the error msg
[[email protected] Python-2.7.13]$ python2.7 get-pip.py
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Collecting wheel
Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Exception:
Traceback (most recent call last):
File “/tmp/tmpGCg2kV/pip.zip/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/tmp/tmpGCg2kV/pip.zip/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_set.py”, line 784, in install
**kwargs
File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_install.py”, line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File “/tmp/tmpGCg2kV/pip.zip/pip/req/req_install.py”, line 1064, in move_wheel_files
isolated=self.isolated,
File “/tmp/tmpGCg2kV/pip.zip/pip/wheel.py”, line 345, in move_wheel_files
clobber(source, lib_dir, True)
File “/tmp/tmpGCg2kV/pip.zip/pip/wheel.py”, line 316, in clobber
ensure_dir(destdir)
File “/tmp/tmpGCg2kV/pip.zip/pip/utils/__init__.py”, line 83, in ensure_dir
os.makedirs(path)
File “/usr/lib64/python2.7/os.py”, line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: ‘/usr/lib/python2.7/site-packages/pip’
[[email protected] Python-2.7.13]$
Use –user along with command
python2.7 get-pip.py –user
What about pip for this version of python?
I Eugene, I have added the last step to installed PIP for the installed Python version.
I installed the version 2.7.5 but i don’t find the file python2.7. I d’ont understand.
cmd type = python
start your programing
These steps are simple and easy to replicate across hosts. Worked like a charm. Thanks.
python2.7 -V didn’t work. says cannot find it.
I can run “python” from “/usr/src/Python2.7.13/” and I get the version 2.7.3 but running python2.7 does nothing.
What went wrong? Do I need to run install-sh after doing the “make altinstall” command?
Please help. I’m not familiar with Oracle Linux, I’m used to Ubuntu Server and I’m floundering a bit here.
Excellent
thx drom Russia
Your article helps me to install…
After the installation we are getting the below error when we try to run a command,
[[email protected] home]# vdetect –reseller=xyz
AH00112: Warning: DocumentRoot [/home/*/public_html/web1] does not exist
AH00112: Warning: DocumentRoot [/home/*/public_html/krk.*.com] does not exist
AH00112: Warning: DocumentRoot [/home/*/public_html/home/cistrons/public_html/demo] does not exist
AH00112: Warning: DocumentRoot [/home/*/public_html/web1] does not exist
AH00112: Warning: DocumentRoot [/home/*/public_html/home/innosysc/public_html/demo] does not exist
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/conf/httpd.conf:107656
AH00112: Warning: DocumentRoot [/home/*/public_html/paypal-singin] does not exist
AH00112: Warning: DocumentRoot [/home/*/public_html/paypal-singin] does not exist
Traceback (most recent call last):
File “/root/bin/vdetect”, line 618, in
signatures = ApplicationSignature.get_xml_signatures_from_url(opts.sigloc, opts.useragent)
File “/root/bin/vdetect”, line 218, in get_xml_signatures_from_url
return cls.get_xml_signatures_from_string(urllib2.urlopen(req).read())
File “/usr/local/lib/python2.7/urllib2.py”, line 154, in urlopen
return opener.open(url, data, timeout)
File “/usr/local/lib/python2.7/urllib2.py”, line 429, in open
response = self._open(req, data)
File “/usr/local/lib/python2.7/urllib2.py”, line 447, in _open
‘_open’, req)
File “/usr/local/lib/python2.7/urllib2.py”, line 407, in _call_chain
result = func(*args)
File “/usr/local/lib/python2.7/urllib2.py”, line 1228, in http_open
return self.do_open(httplib.HTTPConnection, req)
File “/usr/local/lib/python2.7/urllib2.py”, line 1198, in do_open
raise URLError(err)
urllib2.URLError:
[[email protected] home]#
It about Windows 7, It doesn’t have python 2.7 and I want to install python 2.7.13 first so how would I do this using batch file? Assume all setups are placed on common location.
Works. Thank you
make altinstall command is failing with the following message:
make: *** No rule to make target ‘altinstall’. Stop
Installed like a charm on an IBM Mainframe. Thanks!
Hi,
This works perfectly.
Could you show how to install pyodbc to this python2.7 altinstall dir?
By default running the pyodbc rpm, it gets install to the python 2.6 dir.
Please advise. thanks.
works gr8
Worked as a charm for me on Centos 6.4. Thank you very for the article.
Thanks.
Just a heads up, if you are on centos/rhel 7, where python2.7.5 is the default, the altinstall option for any other python2.7 version (2.7.11 for instance) will break your installation as it writes to the same /usr/lib/python2.7 directory and destroys the yum modules. I am sure there is a way around this, but I just encountered this issue and it took rebuilding yum from a few RPMs just to get my system back to normal.
How did you do this? I did the same thing and would like to get back to the original situation?
Thanks!
How did you fix this? Is this why pip will not install?
# curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py”
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1558k 100 1558k 0 0 1172k 0 0:00:01 0:00:01 –:–:– 1174k
# python2.7 get-pip.py
Traceback (most recent call last):
File “get-pip.py”, line 20061, in
main()
File “get-pip.py”, line 194, in main
bootstrap(tmpdir=tmpdir)
File “get-pip.py”, line 82, in bootstrap
import pip
zipimport.ZipImportError: can’t decompress data; zlib not available
[[email protected] src]#
Great article! Easy to read and does what it supposed to do. I tried it on Centos6.6
More quickly
yum install centos-release-SCL
yum install python27
scl enable python27 bash
Thank YOu!
thanks, great work!
just a question from a novice, how do i now -use- this altinstall instead of the standard version
e.g. when running plexconnect.py?
Hello Rahul,
I have installed Python 2.7 on centos 5 from source code. Python 2.4 is already there in centos 5. Could you please help me to uninstall Python 2.7 so that I can reinstall it with yum.
Thanks in advance
Worked perfectly and put into simple steps. Very good for someone new to linux. Thanks!