Centos 上安装python3
1、yum方式安装:
查看yum 的python可安装包
yum search python
安装指定的python版本
yum install python3.x86_64 -y
安装完成:
查看安装包的信息:
rpm -qa | grep python3
2、编辑安装:
下载地址:
https://www.python.org/ftp/python/3.11.8/Python-3.11.8.tgz
解压缩包:
tar zxvf Python-3.11.8.tgz
切换到Python-3.11.8目录
cd Python-3.11.8
安装相关依赖:
yum install -y c gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-deve
配置安装路径:
./configure --prefix=/var/python3 --with-openssl=/usr/local/openssl
编译及安装
make && make install
配置环境变量:
vi /etc/profile
在后面添加python3的bin路径
重新读取环境变量信息:
切换root权限:su root
source /etc/profix
安装完成:
问题1:configure: error: no acceptable C compiler found in $PATH
解决方式:需要安装:c gcc 编译器
yum install c gcc -y
问题2:zipimport.ZipImportError: can't decompress data; zlib not available
解决方式:安装解压相关依赖
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-deve
然后删除MakeFile 文件,重新编译./configure --prefix=/var/python3