postgresql 如何将pip指向psycopg2包?

vuv7lop3  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(3)|浏览(127)

我试图安装一个需要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设置时,我可以看到psycopg 2-binary已经安装。我认为这与PATH有关,但我似乎无法解决这个问题。
which psql:/usr/bin/psql
which pg_config:/usr/bin/pg_config
我不喜欢在环境变量中做太多的事情,因为我真的不想破坏一些东西。

wrrgggsh

wrrgggsh1#

看起来你试图安装pscopg 2,如果已经安装了psycopg 2-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

jv2fixgn

jv2fixgn2#

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

ss2ws0br

ss2ws0br3#

psycopg2psycopg2-binary在技术上是两个独立的软件包,尽管它们提供完全相同的功能。它们只是捆绑方式不同。
这是一个很麻烦的方法,但是你可以pip安装psycopg2-binary,然后让pip相信你确实安装了psycopg2。要做到这一点,请转到你的环境的site-packages,并创建psycopg2-2.9.9.dist-info/METADATA文件。该文件可以是空的。
如果您尝试运行pip install psycopg2(或通过其他依赖项间接运行),pip将告诉您Requirement already satisfied

相关问题