pg_config executable not found

后端 未结 30 2450
渐次进展
渐次进展 2020-11-22 15:42

I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2:

Error: pg_config executable not found.

P         


        
30条回答
  •  一向
    一向 (楼主)
    2020-11-22 16:12

    You can install pre-compiled binaries on any platform with pip or conda:

    python -m pip install psycopg2-binary
    

    or

    conda install psycopg2
    

    Please be advised that the psycopg2-binary pypi page recommends building from source in production:

    The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources

    To use the package built from sources, use python -m pip install psycopg2. That process will require several dependencies (documentation) (emphasis mine):

    • A C compiler.
    • The Python header files. They are usually installed in a package such as python-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.
    • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.
    • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH: $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH You only need pg_config to compile psycopg2, not for its regular usage.

提交回复
热议问题