天天看点

ubuntu安装psycopg2报错

pip install psycopg2报错

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

解决办法(我用的是ubuntu20):

这是因为缺少一个依赖包libpq-dev:

执行 sudo apt-get install libpq-dev  

依赖包安装成功之后再次执行pip install psycopg2即可

参考博客 https://www.cnblogs.com/iminic/p/4092918.html