centos7.3 安装python
查看当前python情况
[root@localhost /]# cd /
[root@localhost bin]# cd /usr/bin
[root@localhost bin]# ls python*
python python2 python2.7
[root@localhost bin]# ls -al python*
修改软连接
[root@localhost bin]# mv python python.bak
开始做下载准备
[root@localhost bin]# mkdir /usr/local/python3
[root@localhost bin]# cd /usr/local/python3
开始下载
[root@localhost python3]# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
#解压命令
[root@localhost python3]# tar -xvf Python-3.6.3.tgz
#解压完成后,查看目录下文件
[root@localhost python3]# ll
total 22148
drwxr-xr-x. 17 501 501 4096 Oct 21 12:22 Python-3.6.3
-rw-r--r--. 1 root root 22673115 Oct 3 15:47 Python-3.6.3.tgz
指定python的安装目录
[root@localhost python3]# cd Python-3.6.3/
[root@localhost Python-3.6.3]# ./configure --prefix=/usr/local/python3Dir
编译文件
[root@localhost Python-3.6.3]# make
[root@localhost Python-3.6.3]# make install
创建一个python3的软链接
[root@localhost python3Dir]# cd /usr/bin
[root@localhost bin]# ln -s /usr/local/python3Dir/bin/python3 /usr/bin/python
修改yum,将#!/usr/bin/python改成#!/usr/bin/python2.7
[root@localhost bin]# vi /usr/bin/yum
[root@localhost bin]# vi /usr/libexec/urlgrabber-ext-down
[root@localhost bin]# vi /usr/bin/yum-config-manager
检查下链接情况
[root@localhost bin]# ll -a python*
[root@localhost bin]# python -V
[root@localhost bin]# python3
[root@localhost bin]# python2
[root@localhost bin]# python
#######################################
准备安装pip,下载需要的环境
[root@localhost /]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
[root@localhost /]# yum install -y epel-release
开始安装pip3
[root@localhost /]# yum install python36-pip
检查pip3是否成功
[root@localhost /]# pip3 -V
==================================================================
3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。
#yum install libffi-devel -y
#make install
若在安装前移除了/usr/bin下python的文件链接依赖,此时yum无法正常使用,需要自己下载相关软件包安装,为节省读者时间,放上链接
#wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libffi-devel-3.0.13-18.el7.x86_64.rpm
#rpm -ivh libffi-devel-3.0.13-18.el7.x86_64.rpm
安装完成后重新进行make install,结束后再次配置相关文件的软连接即可。
====================================================================
加入不记得位置,卸载python3方式
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps 卸载pyhton3
whereis python3 |xargs rm -frv 删除所有残余文件
成功卸载!
whereis python 查看现有安装的python