【问题标题】:How to point pip to psycopg2 package?如何将 pip 指向 psycopg2 包?
【发布时间】:2020-03-16 11:01:00
【问题描述】:

我正在尝试安装一个需要 psycopg2 作为依赖项的软件包,因此我使用 pip install psycopg2-binary 安装了 psycopg2-binary 但是当我尝试使用 pip install django-tenant-schemas 时出现此错误:

In file included from psycopg/psycopgmodule.c:27:0:
./psycopg/psycopg.h:34:10: fatal error: Python.h: No such file or directory
     #include <Python.h>
              ^~~~~~~~~~
    compilation terminated.

You may install a binary package by installing 'psycopg2-binary' from PyPI.
If you want to install psycopg2 from source, please install the packages required for the build and try again.

For further information please check the 'doc/src/install.rst' file (also at <http://initd.org/psycopg/docs/install.html>).

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

ERROR: Command errored out with exit status 1: 
/home/david/PycharmProjects/clearpath/venv/bin/python -u 
-c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ckbbq00w/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ckbbq00w/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install
--record /tmp/pip-record-pi6j7x5l/install-record.txt
--single-version-externally-managed
--compile
--install-headers /home/david/PycharmProjects/clearpath/venv/include/site/python3.7/psycopg2 Check the logs for full command output.

当我进入我的项目(使用 PyCharm)repo 设置时,我可以看到 psycopg2-binary 已安装。我认为这与 PATH 有关,但我似乎无法弄清楚如何解决这个问题。

which psql: /usr/bin/psql

which pg_config: /usr/bin/pg_config

我不太愿意在环境变量中做太多事情,因为我真的不想破坏某些东西。

【问题讨论】:

  • 你安装了gcc 吗?
  • 是的。 gcc --version: gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
  • 啊!我会取消删除。非常感谢您通知我。
  • 它没有被删除。

标签: python postgresql


【解决方案1】:

您似乎尝试安装pscopg2,如果已安装psycopg2-binary可能会导致问题

这是您的多行日志:

ERROR: Command errored out with exit status 1: 
/home/david/PycharmProjects/clearpath/venv/bin/python -u 
-c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ckbbq00w/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ckbbq00w/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install
--record /tmp/pip-record-pi6j7x5l/install-record.txt
--single-version-externally-managed
--compile
--install-headers /home/david/PycharmProjects/clearpath/venv/include/site/python3.7/psycopg2 Check the logs for full command output.

我会尝试卸载psycopg2-binary,然后重新安装django-tenant-schemas

【讨论】:

    【解决方案2】:

    问题似乎是 libpq-fe-h 的错误安装,已通过重新安装修复。问题已解决here

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 2016-03-20
      • 2013-12-08
      • 2015-01-03
      • 2020-07-05
      • 2017-02-07
      • 2013-04-01
      相关资源
      最近更新 更多