centos下Python2和Python3共存

由于目前企业生产环境或是脚本代码均是基于Python2.7的,为了保证Linux同时运行Python2和Python3特意整理了此教程,祝大家及时拥抱Python3


更新软件包

yum clean all  # 清楚缓存
yum list 
yum -y update

安装依赖

yum install gcc  # 后端语言必须
yum install gcc-c++   
yum -y groupinstall "Development tools"
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

下载

wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
mkdir /usr/local/python3 
tar -zxvf Python-3.4.2.tgz
cd Python-3.4.2
./configure --prefix=/usr/local/python3  --enable-optimizations
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3

测试

python3
Python 3.4.2 (default, Jul 19 2016, 03:47:32) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

标签: Centos, Python,

更新于: 2018-09-11 00:00