Python psycopg2: pg_config not found

Problem description:

Hey guys I’m not able to make postgress work with python in replit. The problem is that there is no way to install psycopg2.

I saw all of these posts but none of them has any real solution:

I am able to install the psycopg2-binary, that one has no issues but when I click run then replit will try to install the psycopg2 package and it will output the error always:

I think the main problem here is that replit tries to install the psycopg2 again even though it has the psycopg2-binary

Steps to reproduce:

Initiate a new flask repl, write at the top import psycopg2, click run, and watch it fail

This is the error:

Error: pg_config executable not found.

  EnvCommandError

  Command ['/home/runner/QuixoticBonyProfile/venv/bin/pip', 'install', '--no-deps', 'https://files.pythonhosted.org/packages/89/d6/cd8c46417e0f7a16b4b0fc321f4ab676a59250d08fce5b64921897fb07cc/psycopg2-2.9.5.tar.gz#sha256=a5246d2e683a972e2187a8714b5c2cf8156c064629f9a9b1a873c1730d9e245a'] errored with the following return code 1, and output: 
  Looking in indexes: https://package-proxy.replit.com/pypi/simple/
  Collecting https://files.pythonhosted.org/packages/89/d6/cd8c46417e0f7a16b4b0fc321f4ab676a59250d08fce5b64921897fb07cc/psycopg2-2.9.5.tar.gz#sha256=a5246d2e683a972e2187a8714b5c2cf8156c064629f9a9b1a873c1730d9e245a
    Using cached psycopg2-2.9.5.tar.gz (384 kB)
      ERROR: Command errored out with exit status 1:
       command: /home/runner/QuixoticBonyProfile/venv/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-jgx124t6/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-jgx124t6/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'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-eu6rzt5w
           cwd: /tmp/pip-req-build-jgx124t6/
      Complete output (25 lines):
      /home/runner/QuixoticBonyProfile/venv/lib/python3.10/site-packages/setuptools/config/setupcfg.py:463: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      running egg_info
      creating /tmp/pip-pip-egg-info-eu6rzt5w/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-eu6rzt5w/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-eu6rzt5w/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-eu6rzt5w/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-eu6rzt5w/psycopg2.egg-info/SOURCES.txt'
      
      Error: pg_config executable not found.

Expected behavior:

Click run and replit run correctly with psycopg2-binary or replit does not try to install psycopg2.

Here is a Repl I create so you can check it out, Bug appears at this link:

You can check my rpl here: https://replit.com/@fioritonicolas/QuixoticBonyProfile#main.py

Hey @fioritonicolas!

Thank you for reporting this issue. I was able to reproduce the issue and have sent it to the team. I will follow up as soon as I know more.

try after adding postgres via Nix: In shell:

sed -i 's/];/  pkgs.postgresql\n  &/' replit.nix
5 Likes

@UMARismyname is correct. Thank you!

I tried this an it works! Awesome thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.