gpt4 book ai didi

python - 如何安装带有 pg_config 错误的 psycopg2?

转载 作者:太空狗 更新时间:2023-10-29 21:15:24 31 4
gpt4 key购买 nike

我尝试从 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.

我已经获得支持的选项列表,但我不确定从那里去哪里

最佳答案

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

改为安装 psycopg2-binary PyPI 包,它具有适用于 Linux 和 Mac OS 的 Python 轮子。

pip install psycopg2-binary

关于python - 如何安装带有 pg_config 错误的 psycopg2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35104097/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com