First, solve the problem Python2 pip
centos7 comes with a Python2, but did not install pip, we need self-install package called python-pip
# yum install epel-release -y
# yum -y install python-pip
// 安装完成后不是最新的pip版本要进行升级
# pip install --upgrade pip
# pip -V
pip 19.2.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
// 现在可以使用pip进行对Python2 进行安装Python包了
// 第一种方法:
# pip install 包名
// 第二种方法:
# python -m pip install 包名
Second, the installation Python3
Installation dependencies. Note: You can not ignore the relevant package, before I did not install the readline-devel lead to the implementation mode python can not use the keyboard's arrow keys.
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
Download the package.
Note: If you do not use wget command yum -y install wget installed
# wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
Unpack, compile, install
// 解压
# tar -xvJf Python-3.6.8.tar.xz
// 编译
# cd Python-3.6.8
# ./configure prefix=/usr/local/python3
// 安装
# make && make install
Establish flexible connections
cd /usr/bin
rm -f python
rm -f pip
ln -s /usr/local/python3/bin/python3 python3
ln -s /usr/local/python3/bin/python3 python
ln -s /usr/local/python3/bin/python3 py3
ln -s /usr/local/python3/bin/python3 py
ln -s python2 py2
ln -s /usr/local/python3/bin/pip3 pip3
ln -s /usr/local/python3/bin/pip3 pip
// 升级Python3的pip
pip3 install --upgrade pip
test
// 测试
# pip3 -V
pip 19.2.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
// 使用
# pip3 install 包名
// 或者
# python3 -m pip install 包名
Third, the installation completion TAB interpreter (IPython)
py2 -m pip install ipython
py3 -m pip install ipython
// 或者
pip3 install ipython
pip2 install ipython
Set soft links
cd /usr/bin
rm -f ipython
ln -s /usr/local/python3/bin/ipython /usr/bin/ipython3
ln -s /usr/local/python3/bin/ipython /usr/bin/ipython
ln -s /usr/local/python3/bin/ipython /usr/bin/ipy3
ln -s /usr/local/python3/bin/ipython /usr/bin/ipy
ln -s ipython2 ipy2
Fourth, modify the configuration of yum
Since the implementation of yum need python2 version, so we have to modify the configuration of yum
sed -i s/python/python2/ /usr/bin/yum
sed -i s/python/python2/ /usr/libexec/urlgrabber-ext-down
head -1 /usr/bin/yum
head -1 /usr/libexec/urlgrabber-ext-down
After all the steps are completed, my CentOS7 in versions of Python and iPython as follows:
[root@master ~]# ipy -V
7.7.0
[root@master ~]# ipy2 -V
5.8.0
[root@master ~]# python -V
Python 3.6.8
[root@master ~]# python2 -V
Python 2.7.5
[root@master ~]# pip -V
pip 19.2.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
[root@master ~]# pip2 -V
pip 19.2.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)