Ubuntu Pip 安装 psycopg2 错误
错误异常
[...]
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/ubuntu/.virtualenvs/blog/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
[...]
In file included from psycopg/psycopgmodule.c:28:
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
36 | #include <libpq-fe.h>
| ^~~~~~~~~~~~
compilation terminated.
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.
For further information please check the 'doc/src/install.rst' file (also at
<https://www.psycopg.org/docs/install.html>).
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for psycopg2
Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... error
ERROR: Command errored out with exit status 1:
command: /home/ubuntu/.virtualenvs/blog/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1x6hwpno/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/.virtualenvs/blog/include/site/python3.8/psycopg2
cwd: /tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/
[...]
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/ubuntu/.virtualenvs/blog/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ud5yu84v/psycopg2_ebb43fbe607c414196db480068a467fe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1x6hwpno/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/.virtualenvs/blog/include/site/python3.8/psycopg2 Check the logs for full command output.
安装 libpq-dev
libpq-dev 是系统包,必须用操作系统的软件包安装程序来安装
(例如 apt, yum, zypper, dnf, pacman 等)
sudo apt-get install libpq-dev
安装 psycopg2
pip install psycopg2