Error: pg_config executable not found. even though I have added the path to pg_config on environment variable

Question:

I am trying to setup saleor (Django based). I did a “python -m pip install -r requirements.txt” as stated on the website. Things go well until the installation Collecting psycopg2-binary==2.8.3 and then error is thrown. I have Postgre installed and I am on windows. I also have added the path to pg_config on my environment variable since it says pg_config executable not found. I am not sure how to proceed.

Here is the error that is shows up:

ERROR: Command errored out with exit status 1:
     command: 'C:UsersASPIREAppDataLocalProgramsPythonPython38-32python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ASPIRE\AppData\Local\Temp\pip-install-d7c359c_\psycopg2-binary\setup.py'"'"'; __file__='"'"'C:\Users\ASPIRE\AppData\Local\Temp\pip-install-d7c359c_\psycopg2-binary\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-info'
         cwd: C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binary
    Complete output (23 lines):
    running egg_info
    creating C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-infopsycopg2_binary.egg-info
    writing C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-infopsycopg2_binary.egg-infoPKG-INFO
    writing dependency_links to C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-infopsycopg2_binary.egg-infodependency_links.txt
    writing top-level names to C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-infopsycopg2_binary.egg-infotop_level.txt
    writing manifest file 'C:UsersASPIREAppDataLocalTemppip-install-d7c359c_psycopg2-binarypip-egg-infopsycopg2_binary.egg-infoSOURCES.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
    <http://initd.org/psycopg/docs/install.html>).

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.


Any help is appreciated. Thanks

Asked By: Bon Leofen

||

Answers:

The problem was that the environment variable PATH was not set properly. It is used to find executables that are not in the current directory.

For your purposes you don’t have to change the PATH permanently:

  • Open the command line (DOS box) with cmd.exe.

  • Look at the current settings with PATH.

  • Change the value for the current session with

    SET PATH="C:Program FilesPostgreSQL12bin";%PATH%
    

Now it should work.

There is a way to set environment variables permanently on Windows, but they hide it better from version to version. A web search will usually help.

Answered By: Laurenz Albe
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.