Python:安装 psycopg2

安装 psycopg2 的时候,需要添加 PostgreSQL 的 bin 位置到 PATH 中,否则使用 pip 安装 psycopg2 的时候会报错,因为 psycopg2 需要根据 pg_config 获取 PostgreSQL 程序和库的位置:

export PATH=$PATH:/opt/common/postgresql/bin
pip install psycopg2 -i https://pypi.douban.com/simple/

使用 pg_config 可以获取的信息例如:

(venv) [root@hostname pdf]$ pg_config --libdir
/opt/common/postgresql/lib
(venv) [root@hostname pdf]$ pg_config --bindir
/opt/common/postgresql/bin
(venv) [root@hostname pdf]$ pg_config --cc    
gcc
(venv) [root@hostname pdf]$ pg_config --libs
-lpgcommon -lpgport -lpthread -lz -lreadline -lrt -lcrypt -ldl -lm

pg_config 命令的全部选项如下:

(venv) [root@hostname pdf]$ pg_config --help

pg_config provides information about the installed version of PostgreSQL.

Usage:
  pg_config [OPTION]...

Options:
  --bindir              show location of user executables
  --docdir              show location of documentation files
  --htmldir             show location of HTML documentation files
  --includedir          show location of C header files of the client
                        interfaces
  --pkgincludedir       show location of other C header files
  --includedir-server   show location of C header files for the server
  --libdir              show location of object code libraries
  --pkglibdir           show location of dynamically loadable modules
  --localedir           show location of locale support files
  --mandir              show location of manual pages
  --sharedir            show location of architecture-independent support files
  --sysconfdir          show location of system-wide configuration files
  --pgxs                show location of extension makefile
  --configure           show options given to "configure" script when
                        PostgreSQL was built
  --cc                  show CC value used when PostgreSQL was built
  --cppflags            show CPPFLAGS value used when PostgreSQL was built
  --cflags              show CFLAGS value used when PostgreSQL was built
  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built
  --ldflags             show LDFLAGS value used when PostgreSQL was built
  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built
  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built
  --libs                show LIBS value used when PostgreSQL was built
  --version             show the PostgreSQL version
  -?, --help            show this help, then exit

With no arguments, all known items are shown.

Report bugs to <pgsql-bugs@postgresql.org>.

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值