编译安装Python3.6

本文提供在CentOS7系统中安装Python3.6的详细步骤,包括安装编译环境、配置安装路径、解决安装过程中可能遇到的问题等,并确保Python2.7与Python3.6能够共存。
注:环境为CentOS 7 以及 自带的老版Python2.7

一、在官方下载源码包

二、先安装好编译环境
yum install gcc* openssl-devel ncurses ncurses-devel

三、解压安装

tar xf Python-3.6.5.tgz 
cd Python-3.6.5
./configure --prefix=/python36    定义Python3.6的安装目录
make && make install
make clean
make distclean 
/python36/bin/python3 -V    // 查看Python3.6是否安装好
ln -s /python36/bin/python3 /usr/bin/python3    // 创建软连接到/usr/bin下,这样Python2.7和Python3时能共存
四、安装过程遇到的 "坑"  
在make install 出现 zipimport.ZipImportError: can't decompress data; zlib not available
解决:
    yum -y install zlib zlib-devel
在安装好Python3.6时,执行Python3出现: AttributeError: module 'readline' has no attribute 'set_completer'
解决:
    安装模块 "readline"
    https://pypi.org/project/readline/#files    // 下载readline模块安装包,注意:要是源码包
    tar xf readline-6.2.4.1.tar.gz 
    cd readline-6.2.4.1
    python3 setup.py install    // 这步可能出现以下报错
        gcc: error:readline/libreadline.a:no such file or directory
        gcc: error:readline/libhistory.a:no such file or directory
        error: command 'gcc' failed with exit status 1
        解决:
            yum install readline-devel patch 
 安装完Python3.6时,在CentOS7下有2.7和3.6共存,在后期编写的py脚本若是要用到Python3的编译环境时,执行时使用python3命令或者在脚本顶行改成 ----->> #!/usr/bin/python3
最后前面的 “坑”解决完了之后,当你兴致勃勃的使用python3进入交互界面时,发现敲完代码,按下Enter键时,发现报错:Error in `python': munmap_chunk(): invalid pointer:
    解决:
        // python3.6重新安装一遍,就 OK 了,但是感觉还是很泪奔!!!





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值