K
K
k0r0g2021-10-08 15:13:40
Python
k0r0g, 2021-10-08 15:13:40

Why is psycopg2 not installed in the virtualenv?

Installed yesterday my first linux distribution, ubuntu20.04, and wanted to start my projects.

Sequencing:

sudo apt install python3.10
pip install virtualenv
virtualenv -p python3.10 venv

Then I activated the virtual environment and tried to install the requirements. There was a bug with distutils, which was resolved through something like
sudo apt install python3.10-distutils
Here are the requirements. Everything is installed, except for 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


When I write
pip install psycopg2==2.9.1
OR
pip install psycopg2-binary
I catch the error:
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.


Obviously, I googled the line error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
and found this site .
I entered all the commands from there, it did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-10-08
@k0r0g

sudo apt get install libpq-dev.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question