Ask coding questions

← Back to all posts
I need to access postgresql database but psycopg2 does not install
navilaufm (1)

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.

Thanks,

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)

[EnvCommandError]
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'

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source.  Please add the directory

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

Comments
hotnewtop
CoolCoderSJ (613)

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

CoolCoderSJ (613)

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

navilaufm (1)

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

CoolCoderSJ (613)

@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....

navilaufm (1)

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

CoolCoderSJ (613)

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

navilaufm (1)

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 ?

regards

CoolCoderSJ (613)

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

It seems to be working fine for me

FrederikWLC (0)

@navilaufm I am getting that exact same issue