The default system under CentOS7 comes with a version of python2.X. This version is dependent on many programs of the system, so it is not recommended to delete it. If you use the latest Python3, then we know that there is no impact between compiling and installing the source code package and the system default package. So you can install python3 and python2 to coexist.
View centos7's own python version
[ root@localhost ~]# python -V
Python 2.7.5[root@localhost ~]# pip -V
pip 19.0.3from/usr/lib/python2.7/site-packages/pip(python 2.7)
If there is no pip tool under the original python2 version, you can install the pip tool under the Python2 version first:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip -V
Install ipython corresponding to python 2.7 version, here use pip tool to install:
[ root@localhost ~]# pip install ipython
Report an error, install the corresponding package
yum install python-devel libxslt-devel libffi-devel
Installation is complete, check ipython
[ root@localhost ~]# ipython -V
5.8.0[ root@localhost ~]# ipython
Python 2.7.5(default, Oct 302018,23:45:53)
Type "copyright","credits" or "license"for more information.
IPython 5.8.0-- An enhanced Interactive Python.?-> Introduction and overview of IPython's features.%quickref -> Quick reference.
help -> Python's own help system.
object?-> Details about 'object', use 'object??'for extra details.
In [1]:
Install python3
[ root@localhost src]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
[ root@localhost src]# tar xf Python-3.6.4.tgz
[ root@localhost src]# cd Python-3.6.4[root@localhost Python-3.6.4]# ./configure --prefix=/usr/local/python3
[ root@localhost Python-3.6.4]# make && make install
Create soft connection
ln -sv /usr/local/python3/bin/python3 /usr/bin/python3
ln -sv /usr/local/python3/bin/pip3 /usr/bin/pip3
View
[ root@localhost ~]# pip3 -V
pip 9.0.1from/usr/local/python3/lib/python3.6/site-packages(python 3.6)[root@localhost ~]# python3 -V
Python 3.6.4
python3 install ipython
[ root@localhost ~]# pip3 install ipython
Create soft link
ln -sv /usr/local/python3/bin/ipython3 /usr/bin/ipython3
View
[ root@localhost ~]# ipython -V
5.8.0[ root@localhost ~]# ipython3 -V
7.4.0
Because yum uses python2, it may not work properly after replacing it with python3, continue to use this python2.7.5
Therefore modify the yum configuration file (vi /usr/bin/yum).
Change the #!/usr/bin/python in the header of the file to #!/usr/bin/python2.7, save and exit.
Recommended Posts