李守中

Python 与 PostgreSQL

Table of Contents

1 连接到 PostgreSQL 的问题

首先执行 pip install psycopg2 安装驱动包。如果缺少 pg_config 文件会出现以下报错。

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source.  Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

pg_configpostgresql-devel 这个包里,需要安装:

  • Debian 系: sudo apt install libpq-dev
  • Redhat 系: sudo dnf install libpq-devel

如果没有安装 gcc 也会报错:

...
unable to execute 'gcc': No such file or directory

It appears you are missing some prerequisite to build the package from source.

You may install a binary package by installing 'psycopg2-binary' from PyPI.
If you want to install psycopg2 from source, please install the packages
required for the build and try again.
...

sudo dnf install gcc 或者 sudo apt install gcc 安装 gcc 就好了。



Last Update: 2023-08-13 Sun 14:20

Contact: [email protected]     Generated by: Emacs 27.1 (Org mode 9.3)

若正文中无特殊说明,本站内容遵循: 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议