Linux下安装python3.x 与python2 并存

 

 

Linux下安装python3.x 与python2 并存
0.先安装基本依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
1.官网下载编译安装包
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
2.解压
tar -xvJf  Python-3.6.2.tar.xz
3.切换进入python的解压目录
cd Python-3.6.2
4.配置环境
./configure prefix=/usr/local/python3
prefix 软件的安装路径 后面跟具体的安装目录
5.编译 && 安装
make && make install
  安装成功后,/usr/local/目录下就会有python3了
6.因此我们可以添加软链到执行目录下/usr/bin
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
/usr/bin/python3  python3 如果不存在的话会自动创建 
7.在任意目录,输入python3,出现如下提示则安装成功。同时验证python2是否也能正常运行
[doudou@centosaly ~]$ python3
Python 3.6.2 (default, Jul 9 2020, 21:18:16) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
=================================================================
[doudou@centosaly ~]$ python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

 以上,大功告成。

参考来源:https://www.cnblogs.com/zhlblog/p/9499470.html

上一篇:Python2与Python3的区别


下一篇:python2和python3中split的坑