cd opt/目录,执行命令wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz,下载对应版本
执行命令tar -zxvf Python-3.7.6.tgz进行解压
[root@localhost opt]# ll 总用量 22612 drwxr-xr-x. 18 501 501 4096 12月 18 2019 Python-3.7.6 -rw-r--r--. 1 root root 23148187 12月 18 2019 Python-3.7.6.tgz执行命令yum install gcc
执行命令yum install zlib* openssl*
进入到Python-3.7.6/目录中,执行命令./configure --prefix=/usr/python-3.7.6 --enable-optimizations进行预编译
[root@localhost Python-3.7.6]# ./configure --prefix=/usr/python-3.7.6 --enable-optimizations checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.7... no ... ... creating Modules/Setup creating Modules/Setup.local creating Makefile执行命令make install即可
... ... Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-19.2.3 setuptools-41.2.0备注:如果是centos下安装python3.7.0以上版本,需要先执行如下yum -y install libffi-devel命令,再进行make && make install安装,否则会报ModuleNotFoundError: No module named '_ctypes'错误
vi ~/.bashrc是配置当前用户的环境变量,如果需要配置整个系统环境变量则修改etc/profie文件
vi ~/.bashrc增加如下配置,指向python的bin目录
PATH=$PATH:/usr/python-3.7.6/bin立即生效
source ~/.bashrc输入命令python3,即可进入python客户端模式,环境安装完成
[root@localhost bin]# python3 Python 3.7.6 (default, Jul 4 2020, 07:21:23) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit()