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

如果安装后还是找不到新版本sqlite,可尝试编译安装sqlite3时不指定安装目录

还是不行,修改python的setup文件,将sqlite安装路径添加到sqlite_inc_path列表中去

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 --enable-shared --enable-loadable-sqlite-extensions
LD_RUN_PATH=/usr/local/sqlite3/lib make
make
make install

查看编译安装得sqlite版本

sqlite3 -version
3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5

 Python在使用时还是读取老版本sqlite

 [root@localhost ~]# python
Python 3.9.7 (default, Oct  2 2021, 09:05:03) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>>
#设置环境变量
export LD_LIBRARY_PATH="/usr/local python
#再次验证
 [root@localhost ~]# python
Python 3.9.7 (default, Oct  2 2021, 09:05:03) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.36.0'
>>> sqlite3.version
'2.6.0'
>>> 

 或者直接将sqlite得lib文件链接到/usr/lib下

 

posted @ 2018-06-16 16:10  丫丫625202  阅读(250)  评论(0编辑  收藏  举报