centos7下安装多版本python3.6
说明:
centos7下默认安装python2.7.5版本,因为系统环境有依赖默认安装的python2.7.5版本,所以我们不能替换安装系统默认安装Python2.7.5。
所以需要共存安装多版本python3.6.2.
下载python3.6.2(地址可能已经无效,自己去官网下载相应版本)
[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
解压
[root@localhost ~]#tar zxvf Python-3.6.2.tgz
进入目录
[root@localhost ~]#cd Python-3.6.2
自定义安装目录
[root@localhost Python-3.6.2]#./configure --prefix=/usr/lib/python3.6
这个时候安装晕倒问题了,不会往下走,
错误:configure: error: no acceptable C compiler found in $PATH
百度了一下,是没有安装gcc包。
安装gcc包
[root@localhost Python-3.6.2]#yum install gcc
再继续我们的py安装
[root@localhost Python-3.6.2]#./configure --prefix=/usr/lib/python3.6
执行成功
解决在python中按键盘上下键乱码的问题
[root@localhost Python-3.6.2]# vim ./Modules/Setup
把#readline readline.c -lreadline -ltermcap前面的#去掉,保存退出
因为不是覆盖安装所以使用make altinstall进行安装
[root@localhost Python-3.6.2]# make && make altinstall
如果安装过程中出现: 致命错误:readline/readline.h:没有那个文件或目录
执行下面命令
[root@localhost Python-3.6.2]# yum install libtermcap-devel ncurses-devel libevent-devel readline-devel
完成之后继续执行
[root@localhost Python-3.6.2]# make && make altinstall
添加软连接
[root@localhost Python-3.6.2]# ln -s -f /usr/lib/python3.6/bin/python3.6 /usr/bin/python3.6
看到这个结果,大功告成
[root@localhost Python-3.6.2]# python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost Python-3.6.2]# python3.6
Python 3.6.2 (default, Sep 26 2017, 23:31:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost Python-3.6.2]#
好了,这样就有两种python在我们的centos7中运行了,你可以随心所欲的切换版本!