找不到pg_config可执行文件



不知道pg_config是什么,我在网上搜索,它似乎是PostgreSQL的一部分或连接。我没有或从未使用过,但我怀疑我可能会得到这个,因为我最近开始在Python中使用azure库(我以前从未遇到过这个问题)。下面是其中一个错误消息:

WARNING: Discarding https://files.pythonhosted.org/packages/aa/8a/7c80e7e44fb1b4277e89bd9ca509aefdd4dd1b2c547c6f293afe9f7ffd04/psycopg2-2.9.1.tar.gz#sha256=de5303a6f1d0a7a34b9d40e4d3bef684ccc44a49bbe3eb85e3c0bffb4a131b7c (from https://pypi.org/simple/psycopg2/) (requires-python:>=3.6). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Using cached psycopg2-2.9.tar.gz (379 kB)
Preparing metadata (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: 'C:UsersEAppDataLocalProgramsPythonPython310python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\E\AppData\Local\Temp\pip-install-q50_w0n5\psycopg2_b3e7f5e155154965bfc0d5340d85b1ff\setup.py'"'"'; __file__='"'"'C:\Users\E\AppData\Local\Temp\pip-install-q50_w0n5\psycopg2_b3e7f5e155154965bfc0d5340d85b1ff\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89'
cwd: C:UsersEAppDataLocalTemppip-install-q50_w0n5psycopg2_b3e7f5e155154965bfc0d5340d85b1ff
Complete output (23 lines):
running egg_info
creating C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89psycopg2.egg-info
writing C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89psycopg2.egg-infoPKG-INFO
writing dependency_links to C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89psycopg2.egg-infodependency_links.txt
writing top-level names to C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89psycopg2.egg-infotop_level.txt
writing manifest file 'C:UsersEAppDataLocalTemppip-pip-egg-info-ufqtnd89psycopg2.egg-infoSOURCES.txt'
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 ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).

似乎问题不在于路径,而只是我根本没有pg_config。在网上搜索也无济于事;我找到的建议是:

  • 升级pip
  • brew install postgresql(似乎只是为mac ??)
  • 安装psycopg2-binary
  • run which pg_config run
  • whereis pg_config (also tried where)

这些都不起作用。任何以pg_config开头的命令都表示它是一个无法识别的命令。

安装PostgreSQL。当从包安装时,请确保安装包含pg_config, PGXS和C头文件的开发包。

你可能需要把PostgreSQL二进制目录放在PATH:

export PATH=/usr/pgsql-14/bin:$PATH

(当然你必须使用正确的路径)