centos6.7 specific method for installing python2.7.11

  • 2020-05-19 05:12:19
  • OfStack

1. View the local system and python version

# cat /etc/redhat-release
CentOS release 6.7 (Final)
See CentOS release 6.7 (Final) for the python version

# python -V
Python 2.6.6
Note that we do not want to break the system's Python environment, because several key utility applications rely on the system's default Python 2.6.6, and breaking the system's Python environment can lead to a number of unforeseen errors that can cause the system to be reinstalled.

2. Install yum development tools library set and 1 extra package

# yum groupinstall "Development tools"
# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

3. Download and extract the python2.7.11 source package

# wget -c --no-check-certificate https://www.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

4. Compile and install python2.7.11

# ./configure --prefix=/usr/local
# make && make altinstall
Where./configure --prefix= is the specified installation path, according to the official documentation, if you want to install multiple Python runtimes in the same directory, use make altinstall instead of make install

(note: if prefix is not specified, the executable file is placed on /usr /local/bin by default, the library file is placed on /usr/local/lib by default, and the configuration file is placed on /usr/local/etc by default. Other resource files are located at /usr /local/share. To uninstall this program, either use make uninstall once in the original make directory (if make files specify uninstall) or manually delete the relevant file 1 in the above directory.
prefix, just delete 1 folder.)

5. Create soft links for python2.7 execution files

# ln -s /usr/local/bin/python2.7 /usr/local/bin/python
Will/usr local bin/python point/usr/local/bin/python2. 7

6. Test the python version

# sh
sh-4.1# python -V
Python 2.7.11
sh-4.1# exit
exit
# 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.
> > >

We found that the version of Python was detected as 2.7.11 under sh, but it is still the default 2.6.6 under the terminal. This is because it will not take effect until the terminal is restarted. After we restart the terminal:

# python
Python 2.7.11 (default, Feb 24 2016, 09:50:38)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> > >

The python version defaults to our newly installed Python 2.7.11, because in the environment variable PATH /usr/local/bin precedes /usr/bin, which has a high priority:

# echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_60/bin:/root/bin
Or see which python is currently in use:

# which python
/usr/local/bin/python
View the python path:

# whereis python
python: / usr/bin/python2. 6 / usr bin/python/usr/lib/python2. 6 / usr lib64 / python2. 6 / usr/local/bin/python usr/local bin/python2. 7 - config / usr local bin/python2. 7 / usr/local/lib python2. 7 / usr include/python2. 6 / usr share/man man1 / python. 1. gz7. Solve Delete Backspace direction cannot be used

If it is found that the Delete Backspace directional key cannot be used under the python command line, the situation is as follows:

# python
Python 2.7.11 (default, Feb 24 2016, 09:50:38)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
> > > ex^[[D^[[D^[[C^[[C^[[C^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[3~^[[3~^[[3~^C

This is because readline-devel was not installed before compiling and installing python.

The solution is to install readline-devel, then go back to the source package path, re-execute the command to install, you can solve, as follows:

# yum install readline-devel
# cd Python-2.7.11
# make && make altinstall

At this point, we have finished the installation of python2.7.11 under centos6.7!

OK, Enjoy it!!!!!!


Related articles: