Https://www.cnblogs.com/technologylife/p/6242115.html
CentOS system is generally installed by default Python2.6.6 version, a lot of software needs more than 2.7, through the package management tool can not install the latest version, through the source code compiled to facilitate the installation of the specified version, only need to replace the following version of the number of the version you want.
1. Installation Steps
Download source code
1 |
wget http: //www .python.org /ftp/python/2 .7.12 /Python-2 .7.12.tgz |
Unzip the source code in the download directory
1 |
tar -zxvf Python-2.7.12.tgz |
Enter the extracted folder
Build a folder in/usr/local before compiling python2.7.12
(as a Python installation path to avoid overwriting old versions, old and new versions can coexist)
1 |
mkdir /usr/local/python2 .7.12 |
You need to install the following dependencies before compiling, otherwise the PIP will go wrong under the installation
1 |
yum install openssl openssl-devel zlib-devel gcc sqlite-devel -y |
After installing dependencies, execute the following command
1 |
vim . /Modules/Setup .dist |
Find #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
out the comment and save it (i.e. remove the # number)
Compile the installation in the unzipped directory
12 |
. /configure --prefix= /usr/local/python2 .7.12 --with-zlib make && make install |
The old version is not overwritten at this time, then the original /usr/bin/python
link is changed to another name
1 |
mv /usr/bin/python /usr/bin/python2 .6.6 |
Create a new version of Python's soft link
1 |
ln -s /usr/local/python2 .7.12 /bin/python2 .7 /usr/bin/python |
This time at the command line input
python
The new version of Python will be displayed.
123 |
Python 2.7.12 (default, Oct 13 2016, 03:17:14) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. |
2. Modifying the Yum configuration file
The reason to keep the old version is because Yum relies on Python2.6 to change the Yum configuration file to specify the old Python version.
vim /usr/bin/yum
, the first line is #!/usr/bin/python
modified to#!/usr/bin/python2.6.6
3. Install the latest version of PIP
12 |
wget https: //bootstrap .pypa.io /get-pip .py python get-pip.py |
Before the old version of the words are deleted first rm -rf /usr/bin/pip
)
1 |
ln -s /usr/local/python2 .7.12 /bin/pip2 .7 /usr/bin/pip |
Look at the PIP version.
PIP has been installed and can now be used to download and install various packages.
Installing Ipython
Installing using the Pip method
Installing the ReadLine expansion module
123 |
yum install readline-devel yum install patch pip install readline |
You need to add the Ipython path soft link to the/usr/bin directory
1 |
ln -s /usr/local/python2 .7.12 /bin/ipython /usr/bin/ipython |
At this point Ipython installation is complete
This article refers to the link: http://blog.fazero.me/2016/10/13/centos-update-python/
CentOS Upgrade Python 2.7 and install PIP, Ipython