Centos升级Python

Posted 丫丫625202

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos升级Python相关的知识,希望对你有一定的参考价值。

编辑本博客

官网源码下载:https://www.python.org/downloads/source/

编译安装:

先安装:

yum -y install zlib zlib-devel

yum -y install gcc

yum install libffi-devel -y
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel

yum install libuuid-devel libffi-devel bzip2-devel ncurses-devel gdbm-devel openssl-devel readline-devel lzma xz-devel zlib-devel sqlite-devel python3-devel(python-devel,根据python版本选择)

 

配置后安装:

./configure --prefix=/usr/local/python3.4 --enable-shared --enable-loadable-sqlite-extensions

修改yum文件,有python改为python2

yum命令:

vim /usr/bin/yum

#!/usr/bin/python2

yum命令中下载文件:

vi /usr/libexec/urlgrabber-ext-down

#! /usr/bin/python2

对原python改名:

mv /usr/bin/python /usr/bin/python.old

创建新的链接文件

ln -s /usr/local/python3/bin/python3 /usr/bin/python

 ERROR:

./python3: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory

复制源码下的libpython3.4m.a,libpython3.4m.so,libpython3.4m.so.1.0,libpython3.so 到/usr/lib目录下

load刚复制的模块:/sbin/ldconfig

建立软链接:ln -s /usr/local/python3.4/bin/python3 /usr/bin/python

 

Ubuntu编译安装软件提示:编译器无法创建可执行文件,卸载到gcc和g++后重新安装

sudo apt-get install build-essential

 

py3.7.x需要高版本ssl

 

下载源码包

wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz

./configure --prefix=/usr/local/libressl

make & make install

备份

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl /usr/include/openssl.bak

创建软连接

ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl

ln -s /usr/local/libressl/include/openssl /usr/include/openssl

echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf

重新加载

ldconfig -v

验证是否安装完成

openssl version

export LDFLAGS="-L/usr/local/libressl/lib"

export CPPFLAGS="-I/usr/local/libressl/include"

export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

重新编译安装python

import ssl没有报错,说明升级成功!

升级Sqlite版本,编译安装python

下载最新版本sqlite源码,编译安装

如果安装目录为/usr/local/sqlite

python安装指定如下参数

LD_RUN_PATH=/usr/local/sqlite3/lib ./configure LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I/usr/local/sqlite3/include"  --prefix=/usr/local/python3.8
LD_RUN_PATH=/usr/local/sqlite3/lib make
make
make install

 

以上是关于Centos升级Python的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7+Python3.6+Flask环境MySQL5.7升级MySQL8.0

centos怎么升级python

centos 中如何将python更新到最新的版本

centos7 一键升级python3

Centos下升级Python

CentOS 升级 Python3 (附带: 一键升级脚本)