Centos7 python3安装
程序员文章站
2022-03-03 16:56:00
...
centos7 默认安装了python2
[[email protected] scripts]# python -V
Python 2.7.5
进入到/usr/bin目录,查看python文件
[[email protected] bin]# ll *python*
-rwxr-xr-x 1 root root 11312 Apr 27 22:53 abrt-action-analyze-python
lrwxrwxrwx 1 root root 7 Sep 11 08:37 python -> python2
lrwxrwxrwx 1 root root 9 Sep 11 08:37 python2 -> python2.7
-rwxr-xr-x 1 root root 7216 Jul 13 21:07 python2.7
-rwxr-xr-x 1 root root 1835 Jul 13 21:07 python2.7-config
lrwxrwxrwx 1 root root 16 Sep 11 08:37 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 14 Sep 11 08:37 python-config -> python2-config
可以看到,python指向的是python2,python2指向的才是python2.7,所以实际上python2和python是一样的。
[[email protected] bin]# python2 -V
Python 2.7.5
下面使用源码安装python3
安装环境
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
获取安装文件
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
解压、安装
tar -xvJf Python-3.6.2.tar.xz
cd Python-3.6.2
./configure prefix=/usr/local/python3
make && make install
添加指向python3的软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
查看python版本
[[email protected] Python-3.6.2]# python -V
Python 3.6.2
[[email protected] Python-3.6.2]# python2 -V
Python 2.7.5
[[email protected] Python-3.6.2]# python3 -V
Python 3.6.2