在Linux系统安装python
安装依赖环境
[root@localhost ~]#yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develreadline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz
下载python3
python官方下载地址:https://www.python.org/downloads/
复制链接
输入命令
[root@localhost ~]#cd /opt/
[root@localhost opt]#wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz
解压
[root@localhost opt]#tar -zxvf Python-3.8.11.tgz
[root@localhost opt]#ls
Python-3.8.11 Python-3.8.11.tgz rh
[root@localhost opt]#
编译安装(编译安装前需要安装编译器yum install gcc)
[root@localhost opt]#mkdir -p /usr/local/python3
[root@localhost opt]#cd Python-3.8.11/
[root@localhost Python-3.8.11]#yum install gcc
python3.7以后,还需要安装新的包 libffi-devel
[root@localhost Python-3.8.11]#yum install libffi-devel -y
生成编译脚本,放到刚创建的文件里
[root@localhost Python-3.8.11]#tar -zxvf Python-3.8.11.tgz
[root@localhost Python-3.8.11]#./configure --prefix=/usr/local/python3
编译make ,编译时时间挺长的
[root@localhost Python-3.8.11]#make
编译成功之后,安装
[root@localhost Python-3.8.11]#make install
检查python3.8的编译器
[root@localhost Python-3.8.11]#/opt/local/python3/bin/python3.8
Python 3.8.11 (default, Oct 7 2021, 05:30:17)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ('Hello,python')
Hello,python
>>>
做个软链接
[root@localhost Python-3.8.11]#ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost Python-3.8.11]#ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
修改配置文件
刷新
[root@localhost Python-3.8.11]#source ~/.bash_profile
此时Linux就安装上python3了