系统环境:centos 7.x
Python 版本:Python-3.8.0
1. 环境依赖
Python3.x 的安装需要依赖这四个组件:gcc, zlib,zlib-devel,openssl-devel,需要大家预先安装,一次性安装四个组件命令如下:
[xiaokang@hadoop ~]$ sudo yum -y install gcc zlib zlib-devel openssl-devel
2. 下载编译
Python 源码包下载地址: https://www.python.org/downloads/
[xiaokang@hadoop python]$ wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
3. 解压编译
[xiaokang@hadoop python]$ tar -zxvf Python-3.8.0.tgz
进入根目录进行编译,可以指定编译安装的路径,这里我们指定为 /opt/moudle/python3.8
:
[xiaokang@hadoop python]$ cd Python-3.8.0/
[xiaokang@hadoop Python-3.8.0]$ ./configure --prefix=/opt/moudle/python3.8
[xiaokang@hadoop Python-3.8.0]$ make && make install
Successfully installed pip-19.2.3 setuptools-41.2.0
4. 环境变量配置
[xiaokang@hadoop ~]$ sudo vim /etc/profile
export PYTHON_HOME=/opt/moudle/python3.8
export PATH=${PYTHON_HOME}/bin:$PATH
或
export PATH=${JAVA_HOME}/bin:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:${ZOOKEEPER_HOME}/bin:${HIVE_HOME}/bin:${ZEPPELIN_HOME}/bin:${HBASE_HOME}/bin:${SQOOP_HOME}/bin:${FLUME_HOME}/bin:${PYTHON_HOME}/bin:$PATH
使得配置的环境变量立即生效:
[xiaokang@hadoop ~]$ source /etc/profile
5. 验证安装是否成功
输入 python3
命令,如果能进入 python 交互环境,则代表安装成功:
[xiaokang@hadoop ~]$ python3
Python 3.8.0 (default, Apr 4 2020, 08:21:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 11+24
35
>>> exit()
[xiaokang@hadoop ~]$