安装依赖
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 gcc libffi-devel
创建一个目录存放python3安装包,把python.tar包放到此目录下
mkdir /app
解压文件
tar -zxvf Python-3.7.1.tgz
进入目录二进制编译安装
cd Python-3.7.1/
安装目录为/usr/local/python3
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
make
make install
尝试打开python程序
/usr/local/python3/bin/python3.7
退出
>>> exit()
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
vim /etc/profile
最底部添加:
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
验证:
[root@filebeat python]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@filebeat python]# python3 -V
Python 3.7.1
完成