如何在Fedora Linux上安装psycopg2

3

尝试安装psycopg2时出现错误 pip install psycopg2

我不知道是否有pg_config。我尝试找出pg_config和psql的位置,但我不理解为什么我已经安装了PostgreSQL(11.4),但pg_config没有在系统中。如果它确实存在于系统中,如何设置路径以便进行psycopg2安装。

(myvenv) [jpsofficedev@localhost djangogirls]$ postgres --version
postgres (PostgreSQL) 11.4
(myvenv) [jpsofficedev@localhost djangogirls]$ echo $PATH
/home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin:/home/jpsofficedev/.local/bin:/home/jpsofficedev/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/Library/PostgreSQL/11.4/bin
(myvenv) [jpsofficedev@localhost djangogirls]$ which psql
/usr/bin/psql
(myvenv) [jpsofficedev@localhost djangogirls]$ which pg_config
/usr/bin/which: no pg_config in (/home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin:/home/jpsofficedev/.local/bin:/home/jpsofficedev/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/Library/PostgreSQL/11.4/bin)


Collecting psycopg2
  Using cached https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /home/jpsofficedev/Documents/coding_for_girls/djangogirls/myvenv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-w3r253fu/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-w3r253fu/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /tmp/pip-install-w3r253fu/psycopg2/
    Complete output (23 lines):
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

    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.

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

    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 19.2.2, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

在某些发行版中,像 pg_config 这样的东西是从主包中分离出来的。寻找一个名称中带有类似 devdevel 的 PostgreSQL 包。 - Eelke
2
谢谢。sudo yum install libpq-devel python-devel 帮助我安装了依赖项,然后运行了 pip install psycopg2 命令。 - Bhawana Badlani
3个回答

1

根据一个用户的建议,我使用了这些命令,它对我起作用了。

 sudo dnf install python-devel postgresql-devel rpm-build
 pip install psycopg2

似乎在没有rpm-build的情况下工作正常。 - Razze

1

这对我有用

sudo yum install python-devel postgresql-devel rpm-build
pip install psycopg2

-1

OP把这个作为评论了。对我也起作用。最好你把这个作为答案添加进去。

sudo yum install libpq-devel python-devel


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接