今天在安装部分服务的时候,由于系统 CentOS 中默认带了 Python2,但是我的项目需要是 Python3 支持,特此将整个安装步骤记录下来。
安装必要的依赖
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install gcc -y
安装 Python3
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
需要注意的是这里由于是下载国外的包,国内下载建议使用国内镜像源
mv Python-3.7.4.tgz /usr/local/
mkdir /usr/local/python3
cd /usr/local/ && tar -xvf Python-3.7.4.tgz && cd /usr/local/Python-3.7.4/
./configure --prefix=/usr/local/python3
yum install -y libffi-devel
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
python3
如果返回以下信息,标记安装成功
Python 3.7.4 (default, Sep 6 2020, 09:22:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.