ubuntu 20+ 安装psycopg2异常
pip install psycopg2==2.8.6
root@hmm-ELK:/mnt# pip install psycopg2==2.8.6 Collecting psycopg2==2.8.6 Downloading psycopg2-2.8.6.tar.gz (383 kB) |████████████████████████████████| 383 kB 11 kB/s ERROR: Command errored out with exit status 1: command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gefmyxjj/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gefmyxjj/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 /tmp/pip-install-gefmyxjj/psycopg2/pip-egg-info cwd: /tmp/pip-install-gefmyxjj/psycopg2/ Complete output (23 lines): running egg_info creating /tmp/pip-install-gefmyxjj/psycopg2/pip-egg-info/psycopg2.egg-info writing /tmp/pip-install-gefmyxjj/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO writing dependency_links to /tmp/pip-install-gefmyxjj/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt writing top-level names to /tmp/pip-install-gefmyxjj/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt writing manifest file '/tmp/pip-install-gefmyxjj/psycopg2/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 <https://www.psycopg.org/docs/install.html>). ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
需要安装 libpq-dev
apt install libpq-dev
root@hmm-ELK:/mnt# apt install libpq-dev 正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 将会同时安装下列软件: libpq5 建议安装: postgresql-doc-12 下列【新】软件包将被安装: libpq-dev libpq5 升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 127 个软件包未被升级。 需要下载 254 kB 的归档。 解压缩后会消耗 1,009 kB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 libpq5 amd64 12.19-0ubuntu0.20.04.1 [116 kB] 获取:2 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 libpq-dev amd64 12.19-0ubuntu0.20.04.1 [137 kB] 已下载 254 kB,耗时 1秒 (206 kB/s) 正在选中未选择的软件包 libpq5:amd64。 (正在读取数据库 ... 系统当前共安装有 318013 个文件和目录。) 准备解压 .../libpq5_12.19-0ubuntu0.20.04.1_amd64.deb ... 正在解压 libpq5:amd64 (12.19-0ubuntu0.20.04.1) ... 正在选中未选择的软件包 libpq-dev。 准备解压 .../libpq-dev_12.19-0ubuntu0.20.04.1_amd64.deb ... 正在解压 libpq-dev (12.19-0ubuntu0.20.04.1) ... 正在设置 libpq5:amd64 (12.19-0ubuntu0.20.04.1) ... 正在设置 libpq-dev (12.19-0ubuntu0.20.04.1) ... 正在处理用于 libc-bin (2.31-0ubuntu9.16) 的触发器 ... 正在处理用于 man-db (2.9.1-1) 的触发器 ...
安装:
pip install psycopg2==2.8.6
root@hmm-ELK:/mnt# pip install psycopg2==2.8.6 Collecting psycopg2==2.8.6 Using cached psycopg2-2.8.6.tar.gz (383 kB) Building wheels for collected packages: psycopg2 Building wheel for psycopg2 (setup.py) ... - \ done Created wheel for psycopg2: filename=psycopg2-2.8.6-cp38-cp38-linux_x86_64.whl size=505069 sha256=c06251bb215c7b811c1b0d1e4b6f76ae0ff9343e7298d8a9d31c1d9c18acef94 Stored in directory: /root/.cache/pip/wheels/70/5e/69/8a020d78c09043156a7df0b64529e460fbd922ca065c4b795c Successfully built psycopg2 Installing collected packages: psycopg2 Successfully installed psycopg2-2.8.6