在Linux下安装Python(centos7)

Python安装

linux安装步骤:

yum安装依赖:

yum -y install wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make zlib zlib-devel libffi-devel`

进入python官网——>选择相应版本——>找到linux源码安装

右击复制链接地址,在linux中执行如下命令并解压

wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz
?
tar -xvf Python-3.10.4.tgz

解压完成之后进入cd Python-3.10.4/目录下——>开始源码编译前相关配置、检查并开始编译

./configure --prefix=/usr/local/python3.10.4      --prefix指定安装路径
?
 make && make install

进入到cd /usr/local/python3.10.4/目录下,找到bin目录查看有python3.10(稍后要做软链接)

 rm -rf /usr/bin/python    删除linux自带的python
?
ln -s /usr/local/python3.10.4/bin/python3.10 /usr/bin/python 将python3.10指定为默认

修改原python的yum库配置文件(保证我们的yum程序不受影响)

vim /usr/libexec/urlgrabber-ext-down
vim /usr/bin/yum
?
?
#! /usr/bin/python2        两个文件都只在第一行后面加2即可

直接运行python即可

[root@test ]# python
Python 3.10.4 (main, May  1 2023, 01:16:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
?
> >> 

至此,在Linux上安装python完成!!!