如何安装有pg_config错误的psycopg2?

2024-04-29 08:11:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从this site安装psycopg2(PostgreSQL数据库适配器),但是当我试图在cd之后安装到包中并写入

python setup.py install 

我得到以下错误:

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 ...

or with the pg_config option in 'setup.cfg'.

我也试过“sudo pip install psycopg2”,得到了同样的消息。

在阅读docs之后,它要求查看setup.cfg文件(如下所示):

[build_ext]
define=

# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
# PSYCOPG_DEBUG can be added to enable verbose debug information

# "pg_config" is required to locate PostgreSQL headers and libraries needed to
# build psycopg2. If pg_config is not in the path or is installed under a
# different name uncomment the following option and set it to the pg_config
# full path.
#pg_config=

# Set to 1 to use Python datetime objects for default date/time representation.
use_pydatetime=1

# If the build system does not find the mx.DateTime headers, try
# uncommenting the following line and setting its value to the right path.
#mx_include_dir=

# For Windows only:
# Set to 1 if the PostgreSQL library was built with OpenSSL.
# Required to link in OpenSSL libraries and dependencies.
have_ssl=0

# Statically link against the postgresql client library.
#static_libpq=1

# Add here eventual extra libraries required to link the module.
#libraries=

但是,我不确定是否要编辑此文件,因为文档说明如下:

then take a look at the setup.cfg file.

Some of the options available in setup.cfg are also available as command line arguments of the build_ext sub-command. For instance you can specify an alternate pg_config version using:

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

Use python setup.py build_ext --help to get a list of the options supported.

我已经得到了支持的选项列表,但我不知道从那里该怎么做


Tags: andthetopathinpybuildconfig
3条回答

如果你在Ubuntu上试试

sudo apt-get install python-psycopg2

否则,您需要为您的发行版找到并安装Postgresql客户端软件包。psycopg2 installation from source

Debian/Ubuntu

Python 2

sudo apt install libpq-dev python-dev

Python 3

sudo apt install libpq-dev python3-dev

附加

If none of the above solve your issue, try

sudo apt install build-essential
or

sudo apt install postgresql-server-dev-all

如果需要在不编译的情况下安装:

pip install psycopg2-binary

相关问题 更多 >