我们原装的centos上是有python2.7的,不建议删除,可以做个python3共存的。
输入Python命令,查看可以得知是Python2.7.5版本
# python Python 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
查看原装python路径
# which python /usr/bin/python
可以查看位置,一般是位于/usr/bin/python目录下。
下面介绍安装Python3的方法
首先安装依赖包,这个比较多,我这里写的的比较全,要是有时候make或者make install 出现问题,大部分都是依赖包缺失或者损坏,需要一次性安好。
# 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 # yum -y install gcc gcc-c++ zlib zlib-devel libffi-devel
然后根据自己需求下载不同版本的Python3,我下载的是Python3.7.0的tar包,直接常规操作即可
# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz # tar -xvf Python-3.7.0b3.tgz # cd Python-3.7.0b3/ # ./configure --prefix=/data/soft/python/ # make && make install
创建软连接
# ln -s /data/soft/python/bin/python3 /data/soft/python3 # ln -s /data/soft/python/bin/pip3 /data/soft/pip3
加入path路径
# vim /etc/profile 加入下面两行 PATH=/data/soft/python/bin:/data/soft/python/lib:$PATH export PATH
执行变量,让设置的路径生效
# source /etc/profile
在命令行中输入python3测试
# python3 Python 3.7.0b3 (default, May 2 2018, 13:55:41) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
大功告成,写完收工!!!