Cannot install psycopg2

Hi there! cannot install psycopg2 both manually and automatically

Traceback (most recent call last):
  File "main.py", line 23, in <module>
    import mydb
  File "/home/runner/enraidaiogram/mydb.py", line 1, in <module>
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
 

Replit Profile: https://replit.com/@AskhatUrazbaev

What command did you run to try to install it, and what was the output of the command?

Through Packages interface

Have you tried doing
pip install psycopg2or
poetry add psycopg2 in the shell?

2 Likes

I would recommend using the poetry command as @QuantumCodes suggested: poetry add psycopg2, then also for good measure and to be safe, try poetry update. I’ve sometimes resolved issues with packages just by running poetry update.

1 Like

This is what I got after using poetry add psycopg2

Updating dependencies
Resolving dependencies... (1.3s)

Package operations: 1 install, 0 updates, 0 removals

  • Installing psycopg2 (2.9.6): Failed

  EnvCommandError

  Command ['/home/runner/enraidaiogram/venv/bin/pip', 'install', '--no-deps', 'https://files.pythonhosted.org/packages/af/c4/5726cddb53fe52f0e839eb3da04322364f14493217ebd5818cc5e4c948a5/psycopg2-2.9.6.tar.gz#sha256=f15158418fd826831b28585e2ab48ed8df2d0d98f502a2b4fe619e7d5ca29011'] 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/af/c4/5726cddb53fe52f0e839eb3da04322364f14493217ebd5818cc5e4c948a5/psycopg2-2.9.6.tar.gz#sha256=f15158418fd826831b28585e2ab48ed8df2d0d98f502a2b4fe619e7d5ca29011
    Downloading psycopg2-2.9.6.tar.gz (383 kB)
      ERROR: Command errored out with exit status 1:
       command: /home/runner/enraidaiogram/venv/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-xgnj5jtn/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-xgnj5jtn/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-2u4_4eh8
           cwd: /tmp/pip-req-build-xgnj5jtn/
      Complete output (25 lines):
      /home/runner/enraidaiogram/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-2u4_4eh8/psycopg2.egg-info
      writing /tmp/pip-pip-egg-info-2u4_4eh8/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /tmp/pip-pip-egg-info-2u4_4eh8/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /tmp/pip-pip-egg-info-2u4_4eh8/psycopg2.egg-info/top_level.txt
      writing manifest file '/tmp/pip-pip-egg-info-2u4_4eh8/psycopg2.egg-info/SOURCES.txt'
      
      Error: pg_config executable not found.
      
      pg_config is required to build psycopg2 from source.  Please add the directory
      containing pg_config to the $PATH or specify the full executable path with the
      option:
      
          python setup.py build_ext --pg-config /path/to/pg_config build ...
      
      or with the pg_config option in 'setup.cfg'.
      
      If you prefer to avoid building psycopg2 from source, please install the PyPI
      'psycopg2-binary' package instead.
      
      For further information please check the 'doc/src/install.rst' file (also at
      <https://www.psycopg.org/docs/install.html>).
      
      ----------------------------------------
  WARNING: Discarding https://files.pythonhosted.org/packages/af/c4/5726cddb53fe52f0e839eb3da04322364f14493217ebd5818cc5e4c948a5/psycopg2-2.9.6.tar.gz#sha256=f15158418fd826831b28585e2ab48ed8df2d0d98f502a2b4fe619e7d5ca29011. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  

  at venv/lib/python3.10/site-packages/poetry/utils/env.py:1195 in _run
      1191│                 output = subprocess.check_output(
      1192│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1193│                 )
      1194│         except CalledProcessError as e:
    → 1195│             raise EnvCommandError(e, input=input_)
      1196│ 
      1197│         return decode(output)
      1198│ 
      1199│     def execute(self, bin, *args, **kwargs):

Try adding psycopg2-binary instead, or see if there’s a nix pkg for pg_config.

1 Like

Adding psycopg2-binary worked! Thanks a lot!

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