1、下载安装包
cd opt/
目录,执行命令wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
,下载对应版本
2、解压
执行命令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
3、安装编译环境
执行命令yum install gcc
4、安装依赖环境
执行命令yum install zlib* openssl*
5、预编译
进入到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
6、安装
执行命令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'
错误
7、环境变量配置
vi ~/.bashrc
是配置当前用户的环境变量,如果需要配置整个系统环境变量则修改etc/profie
文件
vi ~/.bashrc
增加如下配置,指向python的bin目录
PATH=$PATH:/usr/python-3.7.6/bin
立即生效
source ~/.bashrc
8、验证
输入命令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()