【发布时间】:2022-01-26 09:15:05
【问题描述】:
当我尝试安装依赖项时出现以下错误 ,
./psycopg/psycopg.h:35:10:致命错误:libpq-fe.h:没有这样的文件或 目录 35 | #include
取决于:libpq5 (= 12.9-0ubuntu0.20.04.1) 但 14.1-2.pgdg20.04+1 是 待安装
【问题讨论】:
标签: python postgresql psycopg2
当我尝试安装依赖项时出现以下错误 ,
./psycopg/psycopg.h:35:10:致命错误:libpq-fe.h:没有这样的文件或 目录 35 | #include
取决于:libpq5 (= 12.9-0ubuntu0.20.04.1) 但 14.1-2.pgdg20.04+1 是 待安装
【问题讨论】:
标签: python postgresql psycopg2
此错误来自您的 Ubuntu 系统上没有安装 libpq-dev 软件包。
您可以通过安装该软件包或使用 pip 中的 psycopg2-binary 软件包而不是 psycopg2 软件包来解决此问题。 psycopg2-binary 包包含一个预编译的二进制文件,这意味着您在安装应用程序的依赖项时不必构建 C 扩展。
所以,行动计划:
要么,你确保根据psycopg2 documentation在Ubuntu上安装依赖包:
sudo apt install python3-dev libpq-dev
然后您应该能够使用pip install -r requirements.txt 运行您的要求。
另一种选择是更改requirements.txt 文件中的psycopg2 行,使其改为psycopg2-binary,这样您就不必安装libpq-dev 包。
您可以在稍长的installation documentation 中阅读更多关于psycopg2 和psycopg2-binary 之间的区别
【讨论】:
Depends: libpq5 (= 12.9-0ubuntu0.20.04.1) but 14.1-2.pgdg20.04+1 is to be installed 和psycopg2-binary 已安装
The other option is to change the psycopg2 line in your requirements.txt file so that it says psycopg2-binary instead, and then you shouldn't have to install the libpq-dev package.