一、源码安装
1.安装依赖软件包
安装开发工具包
[root@localhost ~]# yum groupinstall "Development Tools" -y
[root@localhost ~]#
[root@localhost ~]# yum -y install zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel libffi-devel
官网下载python软件包
[root@localhost ~]# wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
2.解压安装
[root@localhost ~]# tar -xf Python-3.7.6.tar.xz
[root@localhost ~]# cd Python-3.7.6
[root@localhost Python-3.7.6]#
3.修改配置信息
[root@localhost Python-3.7.6]# sed -ri 's/^#readline/readline/' Modules/Setup.dist
[root@localhost Python-3.7.6]# sed -ri 's/^#(SSL=)/\1/' Modules/Setup.dist
[root@localhost Python-3.7.6]# sed -ri 's/^#(_ssl)/\1/' Modules/Setup.dist
[root@localhost Python-3.7.6]# sed -ri 's/^#([\t]*-DUSE)/\1/' Modules/Setup.dist
[root@localhost Python-3.7.6]# sed -ri 's/^#([\t]*-L\$\(SSL\))/\1/' Modules/Setup.dist
4.开始编译安装
[root@localhost Python-3.7.6]# ./configure --enable-shared
#指定共享库
[root@localhost Python-3.7.6]# make -j 2 && make install
#-j 当前主机的CPU的核心数
二、配置环境
1.配置环境变量
[root@localhost Python-3.7.6]# cmd1='export LD_LIBRARY_PATH='
[root@localhost Python-3.7.6]# cmd2='$LD_LIBRARY_PATH:/usr/local/lib'
[root@localhost Python-3.7.6]# file="/etc/profile.d/python3_lib.sh"
[root@localhost Python-3.7.6]# echo "${cmd1}${cmd2}" >$file
[root@localhost Python-3.7.6]# path="/usr/local/lib"
[root@localhost Python-3.7.6]# file2="/etc/ld.so.conf.d/python3.conf"
[root@localhost Python-3.7.6]# echo ${path} > $file2
使得环境生效
[root@localhost Python-3.7.6]# ldconfig
[root@localhost Python-3.7.6]#
[root@localhost Python-3.7.6]# source /etc/profile
三、测试安装
1.查看python3版本
[root@localhost Python-3.7.6]# python3 -V
[root@localhost Python-3.7.6]# python3
3.测试pip3
pip3是给python安装扩展或第三方模块包
python安装完成!