linux自带的python版本通常是2.X,版本偏低,需要使用更高的版本。
1、登录https://www.python.org/ftp/python/选择自己需要的版本,这里我选择3.7.0
2、linux需要gcc的编译器,gcc --version验证编译器是否存在;
3、安装依赖包:
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 libffi-devel
4、下载Python-3.7.0.tgz ,并上传到linux虚拟机上;
5、解压缩:tar -zxvf Python-3.7.0.tgz
6、创建安装目录:
mkdir -p /usr/local/python3
7、编译安装
#cd Python-3.7.0
#./configure --prefix=/usr/local/python3
#make && make install
8、创建软连接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
9、版本验证
# python3
Python 3.7.0 (default, Apr 16 2019, 07:41:10)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>