2

I want to use postgresql with my Django project, and for that I need to install psycopg2 in my virtualenv. I already have Postgresql 12.2 installed. However, when I run pip install psycopg2, I get the following error:

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

I already found the pg_config executable at /Library/PostgreSQL/12/bin/pg_config, but when I try to add it to the PATH variable using PATH="/Library/PostgreSQL/12/bin/pg_config:$PATH", no success or error message is shown. I have never used the PATH variable before, so I am not sure if I am doing this correctly. When I then try to run which pg_config, it still says "pg_config not found", and when I try to install psycopg2 again, it shows the same error message.

Can anyone help me to solve this problem?

Vojta Ma
  • 21
  • 1
  • 2
  • Does this answer your question? [How to install psycopg2 with pg\_config error?](https://stackoverflow.com/questions/35104097/how-to-install-psycopg2-with-pg-config-error) – abc Apr 26 '20 at 11:19
  • 1
    install psycopg2-binary as suggested in one of the answers in the above link – snakecharmerb Apr 26 '20 at 11:20

1 Answers1

0

Two options

  1. Install POSTGRESQL using brew:

    brew install postgresql

OR

  1. Install psycopg2-binary in your python virtual environment

    pip install psycopg2-binary

Abhi25t
  • 3,703
  • 3
  • 19
  • 32