【Centos 7】安装Pyhton3.8

默认情况下,Linux会自带安装Python,可以运行python --version命令查看
在这里插入图片描述

1.查看当前python版本
# 查看Linux自带的Python2.7版本位置信息
[dyf@iZuf6jf0fjkrh41n5rm60oZ ~]$ which python
/usr/bin/python
# 查看Linux默认安装的Python位置
[dyf@iZuf6jf0fjkrh41n5rm60oZ ~]$ whereis python
python: /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz

# 看到/usr/bin/python和/usr/bin/python2都是软链接,/usr/bin/python指向/usr/bin/python2,而/usr/bin/python2最终又指向/usr/bin/python2.7。所以运行python/python2/python2.7
[dyf@iZuf6jf0fjkrh41n5rm60oZ ~]$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root    7 Feb 27 11:18 /usr/bin/python -> python2
lrwxrwxrwx 1 root root    9 Feb 27 11:18 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 7144 Nov 17 06:23 /usr/bin/python2.7
-rwxr-xr-x 1 root root 1835 Nov 17 06:23 /usr/bin/python2.7-config
lrwxrwxrwx 1 root root   16 Feb 27 11:18 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root   32 Mar 16 11:18 /usr/bin/python3 -> /usr/local/python3/bin/python3.8
lrwxrwxrwx 1 root root   14 Feb 27 11:18 /usr/bin/python-config -> python2-config
2.安装依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
3.安装wget
yum install wget
4.下载源码包
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
5.解压安装
# 解压压缩包
tar -zxvf Python-3.8.1.tgz  

# 进入文件夹
cd Python-3.8.1

# 配置安装位置
./configure prefix=/usr/local/python3

# 安装
make && make install
# 查看是否安装成功
[dyf@iZuf6jf0fjkrh41n5rm60oZ local]# cd /usr/local/
[dyf@iZuf6jf0fjkrh41n5rm60oZ local]# ls
aegis  bin  etc  games  include  lib  lib64  libexec  python3  sbin  share  src
6.添加软连接
#添加python3的软链接 
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3 

#添加 pip3 的软链接 
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
7.测试是否安装成功
[dyf@iZuf6jf0fjkrh41n5rm60oZ ~]$ python3
Python 3.8.1 (default, Mar 16 2021, 11:17:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

想要把Python3链接到python的话,就得修改一下yum的配置

vi /usr/bin/yum 
把 #! /usr/bin/python 修改为 #! /usr/bin/python2 

vi /usr/libexec/urlgrabber-ext-down 
把 #! /usr/bin/python 修改为 #! /usr/bin/python2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值