I need to access postgresql database but psycopg2 does not install

according to some ask posts, seems if I import psycopg2 it does install but when running simple app with flask it never being install.

Trying also pip install psycopg2 in console with same results.


best regards

`Repl.it: Updating package configuration

--> python3 -m poetry add psycopg2
Using version ^2.8.6 for psycopg2

Updating dependencies
Resolving dependencies...

Package operations: 1 install, 0 updates, 0 removals

  • Installing psycopg2 (2.8.6)

Command ['/opt/virtualenvs/python3/bin/pip', 'install', '--no-deps', 'psycopg2==2.8.6'] errored with the following return code 1, and output:
Collecting psycopg2==2.8.6
Using cached psycopg2-2.8.6.tar.gz (383 kB)
ERROR: Command errored out with exit status 1:
command: /opt/virtualenvs/python3/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kvz9d1gq/psycopg2/setup.py'"'"'; file='"'"'/tmp/pip-install-kvz9d1gq/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-licw2_l0
cwd: /tmp/pip-install-kvz9d1gq/psycopg2/
Complete output (23 lines):
running egg_info
creating /tmp/pip-pip-egg-info-licw2_l0/psycopg2.egg-info
writing /tmp/pip-pip-egg-info-licw2_l0/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-licw2_l0/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-licw2_l0/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-licw2_l0/psycopg2.egg-info/SOURCES.txt'

Traceback (most recent call last):
File "main.py", line 1, in <module>
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'`

You are viewing a single comment. View All

Yes, I had the same problem. for repl.it u must install psycopg2-binary.


Note the hyphen, there are two packages named psycopg2ninary, pick the one with the hyphen.


@CoolCoderSJ thanks, added from repl package but don't know is the proper way as still have error, check the screen.


@navilaufm huh, that’s weird.
The error in that image is what I got when installing normal psycopg2, so as the error says, I installed the binary version and it worked for me....


@CoolCoderSJ Yes, how did you installed the binary version?


@navilaufm through the package manager bar on the left, like you were doing...........


I see, @CoolCoderSJ , created a new repl but still same issue, is weird as it is part of the packages, it there a way to report this bug ?



You can report bugs here but this seems to be an issue on ur end -

It seems to be working fine for me


@navilaufm I am getting that exact same issue


@CoolCoderSJ thank you so much for this fix! You were the correct answer after an hour of searching. Much appreciated.