使用 pip 安装 psycopg2 失败,原因是本地没有安装 postgres 数据库
>>> pip install psycopg2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting psycopg2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c9/5e/dc6acaf46d78979d6b03458b7a1618a68e152a6776fce95daac5e0f0301b/psycopg2-2.9.9.tar.gz (384 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 384.9/384.9 kB 1.0 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [23 lines of output]
running egg_info
creating /tmp/pip-pip-egg-info-mn6hq8nn/psycopg2.egg-info
writing /tmp/pip-pip-egg-info-mn6hq8nn/psycopg2.egg-info/PKG-INFO
writing dependency_links to /tmp/pip-pip-egg-info-mn6hq8nn/psycopg2.egg-info/dependency_links.txt
writing top-level names to /tmp/pip-pip-egg-info-mn6hq8nn/psycopg2.egg-info/top_level.txt
writing manifest file '/tmp/pip-pip-egg-info-mn6hq8nn/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
<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: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
可是朕只想装个客户端去连接远程的postgres,看见有的解决方案是先本地装个 postgresql,朕不答应。
仔细看上面的报错说明,其实已经给了解决方案:
If you prefer to avoid building psycopg2 from source, please install the PyPI
‘psycopg2-binary’ package instead.
>>> pip install psycopg2-binary -i https://pypi.tuna.tsinghua.edu.cn/simple/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting psycopg2-binary
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/7a/e806ed82d954b9ec29b62f12ae8929da8910cde5ab7e919ec0983e56672d/psycopg2_binary-2.9.9-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 940.3 kB/s eta 0:00:00
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.9.9
朕很满意
文章讲述了用户在尝试使用pip安装psycopg2时遇到的问题,因为缺少本地PostgreSQL数据库。文章提供了解决方案,即安装psycopg2-binary包,避免源码编译。
922

被折叠的 条评论
为什么被折叠?



