Mud: python2.7 and python3.5 source code installation, python2.7python3.5
This document consistsIlanniwebProviding friendship sponsorship, first launchedThe world
For more articles, follow my ilanniweb
When installing ansible in centos6.6 a few days ago, the system always prompts that the python version is incorrect, resulting in a failure to install ansible. You can only manually install python. To avoid this problem later, we will record the related installation process.
This article uses python2.7 and python3.5 installation as an example.
1. Install python2.7
Before installing python, we first install the various dependent software packages required for python compilation, as shown below:
Yum-y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
After the dependent software package is installed, download the pytho2.7 source code package and perform the following operations:
Wget http://mirrors.sohu.com/python/2.7.12/Python-2.7.12.tar.xz
Tar-xf Python-2.7.12.tar.xz
Cd Python-2.7.12
./Configure -- enable-shared -- enable-loadable-sqlite-extensions -- with-zlib
After the configuration is complete, start compilation and installation as follows:
Make & make install
If the installation is not correct, the correct display is as follows:
Ii. Modify the default python version of the system
The default python version of centos6 series is python2.6.6. If you want to modify the default python version of the system, perform the following operations.
Run the following command to back up python2.6 and create a soft link for python2.7:
Mv/usr/bin/python/usr/bin/python2.6.6
Ln-s/usr/local/bin/python2.7/usr/bin/python
At this point, we can execute the python-V command, if the following error occurs:
Python: error while loading shared libraries: libpython2.7.so. 1.0: cannot open shared object file: No such file or directory
You need to edit the configuration file/etc/ld. so. conf to add a new line of content/usr/local/lib. Save and exit, as shown below:
Vim/etc/ld. so. conf
Include ld. so. conf. d/*. conf
/Usr/local/lib
After the ld. so. conf file is configured, run the following command:
/Sbin/ldconfig
/Sbin/ldconfig-v
Then run the python-V command to view the python version as follows:
You can see that the default python version of the system has been changed to python2.7.
3. Modify yum configurations
After installing python2.7, the yum command may be unavailable due to version reasons. We need to configure the yum command.
We need to back up python2.6 first, and then modify the yum configuration file. If you do not perform this operation, the execution of the yum command will prompt you that your python version is incorrect.
Then, edit the/usr/bin/yum file and paste #! /Usr/bin/python #! /Usr/bin/python2.6.6, as follows:
Vim/usr/bin/yum
#! /Usr/bin/python2.6.6
No error message is displayed when you execute the yum command.
Iv. python3.5 installation command
In the above three chapters, we have introduced the installation of python2.7. In this chapter, we will post the installation command of python3.5, so we will not detail it.
Install related dependencies:
Yum-y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
Install python3:
Wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz
Tar-xf Python-3.5.2.tar.xz
Cd Python-3.5.2
./Configure -- enable-shared -- enable-loadable-sqlite-extensions -- with-zlib
Make & make install
Modify the default python version of the system:
Mv/usr/bin/python/usr/bin/python2.6.6
Ln-s/usr/local/bin/python3/usr/bin/python
Vim/etc/ld. so. conf
/Usr/local/lib
Include ld. so. conf. d/*. conf
/Sbin/ldconfig
Python-V
Modify the python version used by yum:
Vim/usr/bin/yum
#! /Usr/bin/python2.6.6