Linux服务器安装python3环境
Linux服务器默认是2.7.5,但在使用过程中可能需要python3环境,本文介绍如何安装python3
1、 安装python依赖包,主要是gcc编译环境,zlib解压缩包等
yum groupinstall "Development tools" -y
yum install –y --setopt=protected_multilib=false gcc zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、使用源码方式编译安装python3时,必须执行编译安装,否则在安装 Python 库依赖时会有麻烦
cd /usr/local/src
# 下载python3.8.6源码包
wget -c https://www.python.org/ftp/python/3.7.5/Python-3.8.6.tgz
# 解压源码包
tar -zxvf Python-3.8.6.tgz
cd Python-3.8.6
# 编译安装
./configure --prefix=/usr/local --enable-shared && make && make install
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
# 在缓存文件/etc/ld.so.cache中追加进指定目录下的共享库
ldconfig
# 对python3可执行文件建软连接
ln -s /usr/local/bin/python3 /usr/bin/python3
3、验证