源码编译安装 Python
1、卸载自带的 Python(切记不要随便卸载自带 python,我在 openeuler-20.03-sp3 上卸载的时候把 yum 给卸载没了,安装完后配置软连接就好,除非你知道你自己在干什么)
yum remove python3
rpm -qa | grep python3 | xargs rpm -ev --allmatches --nodeps
whereis python3 | xargs rm -frv
2、下载解压最新 Python 源码
curl -O https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
tar -zxvf Python-3.10.6.tgz
3、安装编译需要的包
yum -y install gcc zlib* libffi-devel openssl-devel make
4、源码编译安装
cd Python-3.10.6/ ./configure --prefix=/usr/local/python3 --enable-optimizations make make install
5、创建软连接
rm -rf /usr/bin/python3 /usr/bin/python ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/python3 /usr/bin/python rm -rf /usr/bin/pip3 /usr/bin/pip ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
6、添加 python 库配置信息
echo "/usr/local/python3/lib" >> /etc/ld.so.conf.d/python3.conf ldconfig
7、检查新版本
python3 --version
pip3 --version
8、可能遇到的错误
Could not import runpy module
需要安装依赖
yum install yum-utils yum-builddep python
然后执行make
make clean make make install
参考链接:
https://blog.csdn.net/z736248591/article/details/117124631
https://blog.csdn.net/YMY_mine/article/details/103804365
https://www.yisu.com/zixun/224877.html
https://blog.csdn.net/qq_61313949/article/details/124144829
https://blog.csdn.net/m0_68795816/article/details/125206272