PostgreSQL13 安装 psycopg2

 


postgresql选取13.4版本

python分为python2.7与python3.7

psycopg2分为rpm包与tar源码包

一、先安装依赖包

1、安装postgreSQL13

 

 安装步骤

rpm -ivh postgresql13-libs-13.4-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql13-13.4-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql13-server-13.4-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql13-contrib-13.4-1PGDG.rhel7.x86_64.rpm

2、安装postgresql13-devel依赖包

libicu-devel

llvm-toolset-7-clang

llvm5.0-devel

yum -y install libicu-devel

llvm5.0-devel(没有包)

llvm-toolset-7-clang(没有包)

强制安装postgresql13-devel

二、安装psycopg2

1、直接安装rpm包

 

安装后只有python2.7能用

2、使用tar包安装

1)先安装python3.7

安装编译相关工具包

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum install libffi-devel -y

 下载python3.7

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

tar -xvJf Python-3.7.0.tar.xz

编译安装

mkdir /usr/local/python3 #创建编译安装目录

cd Python-3.7.0

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

make && make install

创建软连接

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

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

2)下载适配 python3.7 的tar包

tar -vzxf psycopg2-2.9.1.tar.gz

cd psycopg2-2.9.1/

 

安装前,需要配置 pg_config:

vim setup.cfg

配置 pg_config

 

3)setup.py安装

编译:

python3 setup.py build

安装:

python3 setup.py install

 

三、验证

import psycopg2

 

posted @ 2021-11-08 15:58  耀阳居士  阅读(683)  评论(0编辑  收藏  举报