1. 程式人生 > >centos7安裝python3和ipython

centos7安裝python3和ipython

tst and edit fix python2.x python2.7 figure pac .py

CentOS7下默認系統自帶python2.X的版本,這個版本被系統很多程序所依賴,所以不建議刪除,如果使用最新的Python3那麽我們知道編譯安裝源碼包和系統默認包之間是沒有任何影響的,所以可以安裝python3和python2共存。

查看centos7自帶python版本

[[email protected] ~]# python -V
Python 2.7.5
[[email protected] ~]# pip -V
pip 19.0.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)

如果原來的python2版本下沒有pip工具,可以先安裝Python2版本下的pip工具:

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip -V

安裝python 2.7版本對應的ipython,此處用pip工具安裝:

[[email protected] ~]# pip install ipython

報錯,安裝對應的包

yum install python-devel libxslt-devel libffi-devel

安裝完成,查看ipython

[[email protected] ~]# ipython -V
5.8.0 [[email protected] ~]# ipython Python 2.7.5 (default, Oct 30 2018, 23:45:53) Type "copyright", "credits" or "license" for more information. IPython 5.8.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPythons features. %quickref -> Quick reference. help
-> Pythons own help system. object? -> Details about object, use object?? for extra details. In [1]:

安裝python3

[[email protected] src]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
[[email protected] src]# tar xf Python-3.6.4.tgz 
[[email protected] src]# cd Python-3.6.4
[[email protected] Python-3.6.4]# ./configure --prefix=/usr/local/python3
[[email protected] Python-3.6.4]# make && make install

創建軟連接

ln -sv /usr/local/python3/bin/python3 /usr/bin/python3
ln -sv /usr/local/python3/bin/pip3 /usr/bin/pip3

查看

[[email protected] ~]# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
[[email protected] ~]# python3 -V
Python 3.6.4

python3安裝ipython

[[email protected] ~]# pip3 install ipython

創建軟鏈接

ln -sv /usr/local/python3/bin/ipython3 /usr/bin/ipython3

查看

[[email protected] ~]# ipython -V
5.8.0
[[email protected] ~]# ipython3 -V
7.4.0

因為yum使用python2,因此替換為python3後可能無法正常工作,繼續使用這個python2.7.5

因此修改yum配置文件(vi /usr/bin/yum)。

把文件頭部的#!/usr/bin/python改成#!/usr/bin/python2.7保存退出即可。

centos7安裝python3和ipython