C/C++教程

PostgreSQL13 安装 psycopg2

本文主要是介绍PostgreSQL13 安装 psycopg2,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、先安装依赖包

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

 

这篇关于PostgreSQL13 安装 psycopg2的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!