Проблема при установке утилиты psycopg2
Пытаюсь установить утилиту psycopg2 и выдаёт проблему:
alex-conquer@LAPTOP-EVM4AADF:/mnt/c/Users/USER/PycharmProjects/pythonProject19$
!pip install psycopg2
pip install psycopg2-binary==2.8.6 install psycopg2
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: psycopg2-binary==2.8.6 in /home/alex-conquer/.loc
al/lib/python3.8/site-packages (2.8.6)
Requirement already satisfied: install in /home/alex-conquer/.local/lib/python3.
8/site-packages (1.3.5)
Collecting psycopg2
Using cached psycopg2-2.9.6.tar.gz (383 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: psycopg2
Building wheel for psycopg2 (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [40 lines of output]
/home/alex-conquer/.local/lib/python3.8/site-packages/setuptools/config/se
tupcfg.py:516: SetuptoolsDeprecationWarning: The license_file parameter is depre
cated, use license_files instead.
warnings.warn(msg, warning_class)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-cpython-38/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/psycopg
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -
g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security
-g -fwrapv -O2 -fPIC "-DPSYCOPG_VERSION=2.9.6 (dt dec pq3 ext lo64)" -DPSYCOPG_
DEBUG=1 -DPG_VERSION_NUM=120013 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/usr/include/p
ython3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -I/us
r/include/libxml2 -I/usr/include/mit-krb5 -c psycopg/adapter_asis.c -o build/tem
p.linux-x86_64-cpython-38/psycopg/adapter_asis.o -Wdeclaration-after-statement
In file included from psycopg/adapter_asis.c:28:
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or direct
ory
36 | #include <libpq-fe.h>
| ^~~~~~~~~~~~
compilation terminated.
It appears you are missing some prerequisite to build the package from sou
rce.
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 '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem wit
h pip.
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: subprocess-exited-with-error
× Running setup.py install for psycopg2 did not run successfully.
│ exit code: 1
╰─> [42 lines of output]
/home/alex-conquer/.local/lib/python3.8/site-packages/setuptools/config/se
tupcfg.py:516: SetuptoolsDeprecationWarning: The license_file parameter is depre
cated, use license_files instead.
warnings.warn(msg, warning_class)
running install
/home/alex-conquer/.local/lib/python3.8/site-packages/setuptools/command/i
nstall.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use
build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-cpython-38/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-cpython-38/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/psycopg
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -
g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security
-g -fwrapv -O2 -fPIC "-DPSYCOPG_VERSION=2.9.6 (dt dec pq3 ext lo64)" -DPSYCOPG_
DEBUG=1 -DPG_VERSION_NUM=120013 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/usr/include/p
ython3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -I/us
r/include/libxml2 -I/usr/include/mit-krb5 -c psycopg/adapter_asis.c -o build/tem
p.linux-x86_64-cpython-38/psycopg/adapter_asis.o -Wdeclaration-after-statement
In file included from psycopg/adapter_asis.c:28:
./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or direct
ory
36 | #include <libpq-fe.h>
| ^~~~~~~~~~~~
compilation terminated.
It appears you are missing some prerequisite to build the package from sou
rce.
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 '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem wit
h pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> psycopg2
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Ответы (1 шт):
You may install a binary package by installing 'psycopg2-binary' from PyPI .
Взял с EnSO
Похоже, что в Ubuntu этот заголовок является частью пакета libpq-dev (по крайней мере, в следующих версиях Ubuntu: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 ( Trusty Tahr) и 18.04 (Bionic Beaver)):
/usr/include/postgresql/libpq-fe.h
Поэтому попробуйте установить libpq-dev или его аналог для вашей ОС:
- Для систем Ubuntu/Debian: sudo apt-get install libpq-dev
- В системах Red Hat Linux (RHEL): yum install postgresql-devel
- Для Mac Homebrew: варить установить postgresql
- Для Mac MacPorts PostgreSQL: gem install pg --with-pg-config=/opt/local/lib/postgresql[номер версии]/bin/pg_config
- Для OpenSuse: zypper в postgresql-devel
- Для ArchLinux: pacman -S postgresql-libs\