7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Error: pg_config executable not found

Last updated at Posted at 2021-01-05

WSLの Linux 環境で psycopg2-binarypip 経由でインストールしたときに出たエラー。Pythonのバージョンは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.

pg_config というコマンドが見当たらないと言われている。pg_config が使えればいいtということ。検索すると PostgreSQL のコマンドらしいので、 Linux 環境に PostgreSQL をインストールすればいいと見当がつく。

ソースからビルドすることになるので、シェアドライブラリなどのインストールが必要になりそう。一旦、ライブラリのリポジトリを見に行く。

Issues を眺めてみると、 pg_config について言及されているものがいくつか見つかる。
https://github.com/psycopg/psycopg2/issues/1200 によれば、 Python 3.9 以降の場合は、 2.8.6 以降じゃないと動作しないようだ。

試してみる。まずは2.8.5がインストールできないことを確認する。

$ docker run -it --rm python:3.9-slim bash
$ python -m pip install psycopg2-binary==2.8.5
エラー詳細
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.

予想通り、失敗。続いて2.8.6をインストールしてみる。Issue の報告通りなら成功するはず。

$ 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

解決。pip install psycopg2-binary>=2.8.6 でインストールできる。

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?