- 准备环境
必选
yum install gcc
yum install cpp
yum install gcc-c++
yum install ncurses
yum install ncurses-devel
yum install gd-devel php-gd
yum install zlib-devel
yum install openssl-devel
可选
yum install freetype-devel freetype-demos freetype-utils
yum install libpng-devel libpng10 libpng10-devel
yum install libjpeg-devel
yum install ImageMagick
yum install flex
yum install ImageMagick-devel
-
下载Python3源码
下载地址:https://www.python.org/downloads/source/
我使用的是Python-3.6.8 -
将下载好的Python源码包上传到服务器并解压
tar -xvf Python-3.6.8.tar.xz -C .
- 进入到Python目录编译安装
cd Python-3.6.8
./configure --prefix=/usr/local/python3.6
make && make install
以上编译完成后,没有报错就说明安装成功了。
- 配置Python环境变量
vim /etc/profile
### 添加如下内容
export PYTHON_HOME=/usr/local/python3.6
export PATH=$PYTHON_HOME/bin:$PATH
- 刷新一下Python的环境变量
source /etc/profile
- 验证安装完成
在命令行输入python3验证是否安装完成
python3
Python 3.6.8 (default, May 30 2019, 11:23:59)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>