在Linux系统安装Python

在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

 在Linux系统安装Python

下载python3 

python官方下载地址:https://www.python.org/downloads/

在Linux系统安装Python

复制链接 

在Linux系统安装Python 

 输入命令

[root@localhost ~]#cd /opt/
[root@localhost opt]#wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz

 在Linux系统安装Python

解压 

[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 

在Linux系统安装Python

编译make ,编译时时间挺长的

[root@localhost Python-3.8.11]#make

在Linux系统安装Python

 编译成功之后,安装

[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

修改配置文件 

在Linux系统安装Python

 刷新

[root@localhost Python-3.8.11]#source ~/.bash_profile

此时Linux就安装上python3了

在Linux系统安装Python

 

上一篇:CentOS6 CenOS7 服务管理(大数据学习第二天)


下一篇:阿里云构建Jenkins服务