@k0r0g

Почему не устанавливается psycopg2 в виртуальное окружение?

Установил вчера свой первый linux-дистрибутив, ubuntu20.04 и захотел запустить свои проекты.

Последовательность действий:
sudo apt install python3.10
pip install virtualenv
virtualenv -p python3.10 venv

Дальше активировал виртуальное окружение и попытался установить requirements. Возникла ошибка с distutils, которая решилась через что-то типа
sudo apt install python3.10-distutils
Вот requirements. Всё установилось, кроме psycopg2.
spoiler

amqp==5.0.6
asgiref==3.4.1
billiard==3.6.4.0
celery==5.1.2
certifi==2021.5.30
charset-normalizer==2.0.6
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.2.0
dj-database-url==0.5.0
Django==3.2.7
django-celery-beat==2.2.1
django-celery-results==2.2.0
django-heroku==0.3.1
django-redis==5.0.0
django-timezone-field==4.2.1
gunicorn==20.1.0
idna==3.2
kombu==5.1.0
prompt-toolkit==3.0.20
psycopg2==2.9.1
python-crontab==2.5.1
python-dateutil==2.8.2
python-dotenv==0.19.0
pytz==2021.1
redis==3.5.3
requests==2.26.0
six==1.16.0
sqlparse==0.4.2
urllib3==1.26.6
vine==5.0.0
wcwidth==0.2.5
whitenoise==5.3.0


Когда пишу
pip install psycopg2==2.9.1
ИЛИ
pip install psycopg2-binary
Я ловлю ошибку:
spoiler

Collecting psycopg2-binary
Downloading psycopg2-binary-2.9.1.tar.gz (380 kB)
|████████████████████████████████| 380 kB 1.6 MB/s
Building wheels for collected packages: psycopg2-binary
Building wheel for psycopg2-binary (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/ilya/PycharmProjects/ITAPractice/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/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('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-gz5329py
cwd: /tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/
Complete output (38 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.10
creating build/lib.linux-x86_64-3.10/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.10/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.10
creating build/temp.linux-x86_64-3.10/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 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140000 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/home/ilya/PycharmProjects/ITAPractice/venv/include -I/usr/include/python3.10 -I. -I/usr/include/postgresql -I/usr/include/postgresql/14/server -I/usr/include/libxml2 -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-3.10/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: Нет такого файла или каталога
36 | #include
| ^~~~~~~~~~~~
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
).

error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for psycopg2-binary
Running setup.py clean for psycopg2-binary
Failed to build psycopg2-binary
Installing collected packages: psycopg2-binary
Running setup.py install for psycopg2-binary ... error
ERROR: Command errored out with exit status 1:
command: /home/ilya/PycharmProjects/ITAPractice/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/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('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oq7d3194/install-record.txt --single-version-externally-managed --compile --install-headers /home/ilya/PycharmProjects/ITAPractice/venv/include/site/python3.10/psycopg2-binary
cwd: /tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/
Complete output (38 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.10
creating build/lib.linux-x86_64-3.10/psycopg2
copying lib/errors.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_json.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_range.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/extras.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/errorcodes.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/pool.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/__init__.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/extensions.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/sql.py -> build/lib.linux-x86_64-3.10/psycopg2
copying lib/tz.py -> build/lib.linux-x86_64-3.10/psycopg2
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.10
creating build/temp.linux-x86_64-3.10/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 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext lo64) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=140000 -DHAVE_LO64=1 -DPSYCOPG_DEBUG=1 -I/home/ilya/PycharmProjects/ITAPractice/venv/include -I/usr/include/python3.10 -I. -I/usr/include/postgresql -I/usr/include/postgresql/14/server -I/usr/include/libxml2 -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-3.10/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: Нет такого файла или каталога
36 | #include
| ^~~~~~~~~~~~
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
).

error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/ilya/PycharmProjects/ITAPractice/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7x74j9ki/psycopg2-binary_df21b24910fc4e6da5ddbbf26d49d050/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('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-oq7d3194/install-record.txt --single-version-externally-managed --compile --install-headers /home/ilya/PycharmProjects/ITAPractice/venv/include/site/python3.10/psycopg2-binary Check the logs for full command output.


Очевидно, я гуглил строчку error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
и нашёл вот этот сайт.
Все команды оттуда ввёл, не помогло.
  • Вопрос задан
  • 2540 просмотров
Решения вопроса 1
@alexbprofit
Junior SE
sudo apt get install libpq-dev.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы