0

I need to install psycopg2 for connecting postgresql with django.I have tried this command.

pip install psycopg2

but this message was shown:

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


    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Rafid\AppData\Local\Temp\pip-install-oknhhl43\psycopg2\

I am new to web development so a detailed solution will be helpful...Thanks in advance

  • 3
    Does this answer your question? [pg\_config executable not found](https://stackoverflow.com/questions/11618898/pg-config-executable-not-found) – Joao Vitorino Jun 07 '20 at 14:55
  • Use answer from Parvathirajan Natarajan as the error message stated:"If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead." – Adrian Klaver Jun 07 '20 at 17:50

2 Answers2

2

Install pre-compiled binaries and then install psycopg2

pip install psycopg2-binary
0

The install of psycopg2 is failing because it cannot find a PostgreSQL executable that it runs to find out config details for the local PostgreSQL installation.

There are two alternatives:

  1. Download and install PostgreSQL, make sure it is on the PATH, and rerun pip install psycopg2

    You can get PostgreSQL installer for Windows from the download page.

  2. Run pip install psycopg2-binary instead.


Note that the Psycopg2 installation instructions state that PostgreSQL is a prerequisite.

However, further down it explains that pg_config is only needed at build time.

Stephen C
  • 632,615
  • 86
  • 730
  • 1,096