Error: pg_config executable not found

Error when installing psycopg2-binary via pip in WSL Linux environment. Python version is 3.9.1

    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.

It is said that the command pg_config is missing. It is good if pg_config can be used. If you search for it, it looks like a PostgreSQL command (https://www.postgresql.jp/document/9.2/html/app-pgconfig.html), so you can guess that you should install PostgreSQL in your Linux environment.

Since it will be built from source, it seems that it will be necessary to install shared libraries etc. Go to the library repository once.

If you look at Issues, you'll find some references to pg_config. According to https://github.com/psycopg/psycopg2/issues/1200, Python 3.9 or later doesn't seem to work until 2.8.6 or later.

Try out. First, make sure that 2.8.5 cannot be installed.

$ docker run -it --rm python:3.9-slim bash
$ python -m pip install psycopg2-binary==2.8.5
Error details
Collecting psycopg2-binary==2.8.5
  Downloading psycopg2-binary-2.8.5.tar.gz (381 kB)
     |████████████████████████████████| 381 kB 8.0 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qcdbyewy/psycopg2-binary_6829b82052994eb083b5f67ce9537531/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qcdbyewy/psycopg2-binary_6829b82052994eb083b5f67ce9537531/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-dt29jovq
         cwd: /tmp/pip-install-qcdbyewy/psycopg2-binary_6829b82052994eb083b5f67ce9537531/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-dt29jovq/psycopg2_binary.egg-info
    writing /tmp/pip-pip-egg-info-dt29jovq/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-dt29jovq/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-dt29jovq/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-dt29jovq/psycopg2_binary.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>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

As expected, it failed. Next, try installing 2.8.6. If it is as reported in Issue, it should succeed.

$ python -m pip install psycopg2-binary==2.8.6
Collecting psycopg2-binary==2.8.6
  Downloading psycopg2_binary-2.8.6-cp39-cp39-manylinux1_x86_64.whl (3.0 MB)
     |████████████████████████████████| 3.0 MB 7.9 MB/s 
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6

Solution. You can install it with pip install psycopg2-binary> = 2.8.6.

Recommended Posts

Error: pg_config executable not found
[Error] Symbol not found: _PyUnicodeUCS2_Compare
Python Not Implemented Error
command not found: django-admin
Today's python error: HTTPError: 404 Client Error: Not Found for url:
ERROR: root: code for hash md5 was not found.
filter rollbar python 404 not found
Exception: Jupyter command `jupyter-lab` not found.
Command is not found in sudo
Dealing with key not found error in pacstrap when installing Arch Linux
Error "Entry point not found" when starting Jupyter Notebook in virtual environment
When the Linux command $ yum -y install gives an error (yum: command not found)