无法在 Mac 12.3 上安装 psycopg2,我不断收到此错误

Jos*_*se 10 django psycopg2 backend python-3.x

我最近买了一台 MacBook Pro 并为其设置了一些 python 和 Django 编程,但最终在安装 psycopg2 时遇到了问题,我已经尝试了几件事,但没有一个对我有用,这里留下了错误,

\n
Collecting psycopg2\n  Using cached psycopg2-2.9.3.tar.gz (380 kB)\n  Preparing metadata (setup.py) ... error\n  error: subprocess-exited-with-error\n  \n  \xc3\x97 python setup.py egg_info did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [23 lines of output]\n      running egg_info\n      creating /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info\n      writing /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/PKG-INFO\n      writing dependency_links to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/dependency_links.txt\n      writing top-level names to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/top_level.txt\n      writing manifest file '/private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/SOURCES.txt'\n      \n      Error: pg_config executable not found.\n      \n      pg_config is required to build psycopg2 from source.  Please add the directory\n      containing pg_config to the $PATH or specify the full executable path with the\n      option:\n      \n          python setup.py build_ext --pg-config /path/to/pg_config build ...\n      \n      or with the pg_config option in 'setup.cfg'.\n      \n      If you prefer to avoid building psycopg2 from source, please install the PyPI\n      'psycopg2-binary' package instead.\n      \n      For further information please check the 'doc/src/install.rst' file (also at\n      <https://www.psycopg.org/docs/install.html>).\n      \n      [end of output]\n  \n  note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: metadata-generation-failed\n\n\xc3\x97 Encountered error while generating package metadata.\n\xe2\x95\xb0\xe2\x94\x80> See above for output.\n\nnote: This is an issue with the package mentioned above, not pip.\nhint: See above for details.\n
Run Code Online (Sandbox Code Playgroud)\n

它表明这不是 pip 的问题,而是 setup.py 的问题,但找不到任何东西,

\n

欢迎任何帮助

\n

谢谢

\n

Abh*_*wat 10

正如 Alex 提到的,系统上未安装 PostGreSQL 会引发错误\n安装 PostGreSQL,一切都会正常工作\n试试这个

\n
\xe2\x9d\xaf brew install postgresql\n# If you open a new terminal tab you will see that pg_config is available\n\xe2\x9d\xaf export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"\n\xe2\x9d\xaf export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib -L${HOME}/.pyenv/versions/3.8.10/lib"\n\xe2\x9d\xaf python -V\nPython 3.9.13\n\xe2\x9d\xaf pip install psycopg2-binary==2.8.6```\n
Run Code Online (Sandbox Code Playgroud)\n


小智 9

尝试使用以下命令:

pip3 install psycopg2-binary
Run Code Online (Sandbox Code Playgroud)