Centos7默认安装的是2.7,这里选择安装使用Python3.6.3
安装Python3.6.3
1、安装python3 需要的依赖包
yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc cc
2、下载python源码
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
3、解压和编译
mkdir /usr/local/python3 -p tar xf Python-3.6.3.tgz cd Python-3.6.3 ./configure --prefix=/usr/local/python3 make make install
4、备份旧版python软链接,链接新版本python
[[email protected] ~]# ls -l /usr/bin/python lrwxrwxrwx. 1 root root 9 Oct 20 14:08 /usr/bin/python -> python2 [[email protected] ~]# ls -l /usr/bin/python2 lrwxrwxrwx. 1 root root 9 Oct 20 14:08 /usr/bin/python2 -> python2.7 [[email protected] ~]# ls -l /usr/bin/python2.7 -rwxr-xr-x. 1 root root 7136 Nov 5 2016 /usr/bin/python2.7
mv /usr/bin/python /usr/bin/python.bak ln -s /usr/local/python3/bin/python3 /usr/bin/python ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
5、修改yum配置文件
vim /usr/bin/yum vim /usr/libexec/urlgrabber-ext-down
将第一行指定的python版本改为python2.7(#!/usr/bin/python 改为 #!/usr/bin/python2.7)
6、检验 Python 及 pip 版本
[[email protected] ~]# python -V Python 3.6.3 [[email protected] ~]# pip -V pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
参考原文地址:http://mp.weixin.qq.com/s/9fluqSWaDwkyAUMYiXF8dw(提供了另一种共存方式)
时间: 2024-10-14 09:35:40