我使用的是 Fedora 39 并安装了 PostgreSQL 15.4。现在我正在尝试从 python 连接到它。我无法做到这一点,因为 psycopg2 需要在 $PATH 变量中设置 pg_config 路径。我一开始就找不到它来设置路径。我已经安装了
python3-devel-3.12.1-2.fc39.x86_64
,并听取了帖子 Post_1 和 Post_2 的建议,但问题仍然存在。
which 命令返回以下内容:
thermite@fedora39:~$ which pg_config
/usr/bin/which: no pg_config in (.....<All the path variable entries>.....)
thermite@fedora39:~$ pip install psycopg2
Defaulting to user installation because normal site-packages is not writeable
Collecting psycopg2
Using cached psycopg2-2.9.9.tar.gz (384 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
running egg_info
writing psycopg2.egg-info/PKG-INFO
writing dependency_links to psycopg2.egg-info/dependency_links.txt
writing top-level names to psycopg2.egg-info/top_level.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
<https://www.psycopg.org/docs/install.html>).
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
然后我试图找到pg_config所在的位置但没有找到 我已按照此处的说明安装了 PostgreSQL。
我找到的安装目录如下(其中都不包含pg_config文件)
/var/lib/pgsql
/usr/bin/psql
其他详情
thermite@fedora39:~$ postgres --version
postgres (PostgreSQL) 15.4
thermite@fedora39:~$ sudo dnf install libpq
[sudo] password for thermite:
asbru-cm-release 429 B/s | 488 B 00:01
asbru-cm-release-noarch 400 B/s | 488 B 00:01
asbru-cm-release-source 401 B/s | 488 B 00:01
Fedora 39 - x86_64 - Updates 4.3 kB/s | 5.4 kB 00:01
Package libpq5-16.0-42PGDG.f39.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
thermite@fedora39:~$ sudo dnf install libpq-devel
Last metadata expiration check: 0:00:14 ago on Tuesday 13 February 2024 08:09:00 AM.
Error:
Problem: package libpq-devel-15.3-1.fc39.i686 from fedora requires libpq(x86-32) = 15.3-1.fc39, but none of the providers can be installed
- conflicting requests
- libpq-15.3-1.fc39.i686 from fedora does not belong to a distupgrade repository
- package libpq-devel-15.3-1.fc39.x86_64 from fedora requires libpq(x86-64) = 15.3-1.fc39, but none of the providers can be installed
- problem with installed package libpq5-16.0-42PGDG.f39.x86_64
- installed package libpq5-16.0-42PGDG.f39.x86_64 obsoletes libpq provided by libpq-15.3-1.fc39.x86_64 from fedora
- package libpq5-16.0-42PGDG.f39.x86_64 from pgAdmin4 obsoletes libpq provided by libpq-15.3-1.fc39.x86_64 from fedora
(try to add '--skip-broken' to skip uninstallable packages)
请有人帮我解决这个问题。
您必须安装开发包:
dnf install postgresql15-devel
然后将 PostgreSQL 二进制目录放在你的
PATH
:
export PATH=/usr/pgsql-15/bin:$PATH
现在你已经准备好了。