Article From:https://www.cnblogs.com/fyy-hhzzj/p/9059808.html

1   mv /usr/bin/python    /usr/bin/python.bak 

2   vim    `which yum`        Modify the python name after the interpreter is modified to what MV. Here is MV to /usr/bin/python.bak, referring to the following screenshots.

Note: centos6.x uses the interpreter of python2.6, so the first line of Yum should write the interpreter right.

3  wget ,   tar   ,    cd   ,   ./configure –prefix=/usr/local/python.xxx      make   make  install  2.7The installation of Python variant is like this. Please see the following installation after python3.x.

 wget ,   tar   ,    cd   ,   ./configure –prefix=/usr/local/python.xxx    These are the same ones in front of them. Make becomes make, J, 4, and make or install.

 

 

Turn around: https://www.cnblogs.com/stonehe/p/7944366.html

Preparation environment: CentOS6.8 machine

 

1.View the default Python version of the machine

[root@hlmcent69nma ~]# python -V
Python 2.6.6
[root@hlmcent69nma ~]# whereis python
python: /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz

 

2.Install GCC

[root@hlmcent69nma ~]# yum install gcc -y

 

3.Download the latest Python2.7.x installation package, unpack and enter the specified directory.

Copy code
[root@hlmcent69nma ~]# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
[root@hlmcent69nma ~]# ll Python-2.7.14.tgz 
-rw-r--r--. 1 root root 17176758 Sep 17 02:05 Python-2.7.14.tgz
[root@hlmcent69nma ~]# tar zxvf Python-2.7.14.tgz
[root@hlmcent69nma ~]# cd Python-2.7.14
[root@hlmcent69nma Python-2.7.14]# ll
total 1000
-rw-r--r--.  1 1000 1000  10914 Sep 17 01:38 aclocal.m4
-rwxr-xr-x.  1 1000 1000  44259 Sep 17 01:38 config.guess
-rwxr-xr-x.  1 1000 1000  36515 Sep 17 01:38 config.sub
-rwxr-xr-x.  1 1000 1000 442959 Sep 17 01:38 configure
-rw-r--r--.  1 1000 1000 141572 Sep 17 01:38 configure.ac
drwxr-xr-x. 22 1000 1000   4096 Sep 17 01:38 Demo
drwxr-xr-x. 18 1000 1000   4096 Sep 17 01:55 Doc
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Grammar
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Include
-rwxr-xr-x.  1 1000 1000   7122 Sep 17 01:38 install-sh
drwxr-xr-x. 47 1000 1000  12288 Sep 17 01:38 Lib
-rw-r--r--.  1 1000 1000  12757 Sep 17 01:38 LICENSE
drwxr-xr-x. 11 1000 1000   4096 Sep 17 01:38 Mac
-rw-r--r--.  1 1000 1000  48553 Sep 17 01:38 Makefile.pre.in
drwxr-xr-x.  5 1000 1000   4096 Sep 17 01:38 Misc
drwxr-xr-x.  9 1000 1000   4096 Sep 17 01:38 Modules
drwxr-xr-x.  3 1000 1000   4096 Sep 17 01:38 Objects
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Parser
drwxr-xr-x.  9 1000 1000   4096 Sep 17 01:38 PC
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 PCbuild
-rw-r--r--.  1 1000 1000  35170 Sep 17 01:38 pyconfig.h.in
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Python
-rw-r--r--.  1 1000 1000  55670 Sep 17 01:38 README
drwxr-xr-x.  5 1000 1000   4096 Sep 17 01:38 RISCOS
-rw-r--r--.  1 1000 1000  99231 Sep 17 01:38 setup.py
drwxr-xr-x. 23 1000 1000   4096 Sep 17 01:38 Tools
Copy code

 

4.Configuration, compilation, compilation and installation

[root@hlmcent69nma Python-2.7.14]# ./configure --prefix=/usr/local/python/python2.7
[root@hlmcent69nma Python-2.7.14]# make
[root@hlmcent69nma Python-2.7.14]# make install

Remarks:
Execute./configure –prefix=/usr/local/python/python3Order. After the./configure command is executed, a file creating Makefile is created for the following purposes.The make command uses the execution of makeAfter install, we will install the program into the directory we specified. Configure is an executable script. It has many options to use the command./configure under the source path to be installed.- heLP output detailed list of options. The –prefix option is the path of configuration and installation. If this option is not configured, the executable file after installation is defaults to /usr./local/bin, the library file is placed in /usr/local/lib by default, and the configuration file is placed by default.In /usr/local/etc, other resource files are placed in /usr./local/share, more messy. If –prefix is configured, such as:./configure–prefix=/usr/local/tesT can put all resource files in the path of /usr/local/test, and it will not be messy. Another advantage of using the prefix option is to uninstall software or transplant software. When an installed software is no longer needed, simply remove the installation directory and uninstall the software.It needs to be cleaned up; transplant software simply copies the entire directory to another machine (the same operating system). Of course, to uninstall the program, you can also use make once in the original make directory.Uninstall, but the premise is that the make file specifies uninstall.

 

5.Look at the Python version of the system, or 2.6.x

[root@hlmcent69nma ~]# python -V
Python 2.6.6

 

6.Look at the newly installed Python version, the current version of the system’s Python, and modify the system directed Python from 2.6.x to 2.7.x, and again look at the Python version of the current system, which has been changed to 2.7.x

Copy code
[root@hlmcent69nma ~]# /usr/local/python/python2.7/bin/python2.7 -V
Python 2.7.14
[root@hlmcent69nma ~]# /usr/bin/python -V
Python 2.6.6
[root@hlmcent69nma ~]# mv /usr/bin/python /usr/bin/python.bak
[root@hlmcent69nma ~]# ln -s /usr/local/python/python2.7/bin/python2.7 /usr/bin/python
[root@hlmcent69nma ~]# python -V
Python 2.7.14
Copy code

 

7.However, it was found that the yum command could not be used. Since Yum is based on python2.6, it can work normally, and it needs to point Yum to python2.6 version separately.

Copy code
[root@hlmcent69nma ~]# yum list
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.14 (default, Nov 30 2017, 11:54:55) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
If you cannot solve this problem yourself, please go to 
the yum faq at:
http://yum.baseurl.org/wiki/Faq
Copy code

[root@hlmcent69nma ~]# vim /usr/bin/yum

 

Reference links:

https://www.cnblogs.com/perallina/p/5253329.html

https://www.cnblogs.com/lclq/archive/2016/06/27/5620196.html

 

Leave a Reply

Your email address will not be published. Required fields are marked *