今天在安装服务器环境时,使用Python  安装 psycopg2 报错如下

pip3 install psycopg2
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting psycopg2Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383 kB)|████████████████████████████████| 383 kB 14.7 MB/s
Building wheels for collected packages: psycopg2Building wheel for psycopg2 (setup.py) ... errorERROR: Command errored out with exit status 1:command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6gdzdzy9/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6gdzdzy9/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-b8tz2p9acwd: /tmp/pip-install-6gdzdzy9/psycopg2/Complete output (40 lines):running bdist_wheelrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-3.8creating build/lib.linux-x86_64-3.8/psycopg2copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2running build_extbuilding 'psycopg2._psycopg' extensioncreating build/temp.linux-x86_64-3.8creating build/temp.linux-x86_64-3.8/psycopgx86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120006 -DHAVE_LO64=1 -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statementIn file included from psycopg/psycopgmodule.c:28:./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory36 | #include <libpq-fe.h>|          ^~~~~~~~~~~~compilation terminated.It appears you are missing some prerequisite to build the package from source.You may install a binary package by installing 'psycopg2-binary' from PyPI.If you want to install psycopg2 from source, please install the packagesrequired for the build and try again.For further information please check the 'doc/src/install.rst' file (also at<https://www.psycopg.org/docs/install.html>).error: command 'x86_64-linux-gnu-gcc' failed with exit status 1----------------------------------------ERROR: Failed building wheel for psycopg2Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2Running setup.py install for psycopg2 ... errorERROR: Command errored out with exit status 1:command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6gdzdzy9/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6gdzdzy9/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-056pra4x/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/psycopg2cwd: /tmp/pip-install-6gdzdzy9/psycopg2/Complete output (40 lines):running installrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-3.8creating build/lib.linux-x86_64-3.8/psycopg2copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2running build_extbuilding 'psycopg2._psycopg' extensioncreating build/temp.linux-x86_64-3.8creating build/temp.linux-x86_64-3.8/psycopgx86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120006 -DHAVE_LO64=1 -I/usr/include/python3.8 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.8/psycopg/psycopgmodule.o -Wdeclaration-after-statementIn file included from psycopg/psycopgmodule.c:28:./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory36 | #include <libpq-fe.h>|          ^~~~~~~~~~~~compilation terminated.It appears you are missing some prerequisite to build the package from source.You may install a binary package by installing 'psycopg2-binary' from PyPI.If you want to install psycopg2 from source, please install the packagesrequired for the build and try again.For further information please check the 'doc/src/install.rst' file (also at<https://www.psycopg.org/docs/install.html>).error: command 'x86_64-linux-gnu-gcc' failed with exit status 1----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6gdzdzy9/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6gdzdzy9/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-056pra4x/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/psycopg2 Check the logs for full command output.

原因是因为缺少安装依赖

安装如下依赖:

sudo apt-get install libpq-dev python-dev

安装完成后,在重新安装psycopg2

 sudo apt-get install libpq-dev python-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'python-dev-is-python2' instead of 'python-dev'
The following additional packages will be installed:libpython2-dev libpython2.7 libpython2.7-dev python-is-python2 python2-dev python2.7-dev
Suggested packages:postgresql-doc-12
The following NEW packages will be installed:libpq-dev libpython2-dev libpython2.7 libpython2.7-dev python-dev-is-python2 python-is-python2 python2-dev python2.7-dev
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,948 kB of archives.
After this operation, 18.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 libpq-dev amd64 12.6-0ubuntu0.20.04.1 [136 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe amd64 libpython2.7 amd64 2.7.18-1~20.04.1 [1,038 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe amd64 libpython2.7-dev amd64 2.7.18-1~20.04.1 [2,475 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 libpython2-dev amd64 2.7.17-2ubuntu4 [7,140 B]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python-is-python2 all 2.7.17-4 [2,496 B]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/universe amd64 python2.7-dev amd64 2.7.18-1~20.04.1 [287 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python2-dev amd64 2.7.17-2ubuntu4 [1,268 B]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python-dev-is-python2 all 2.7.17-4 [1,396 B]
Fetched 3,948 kB in 1s (7,438 kB/s)
Selecting previously unselected package libpq-dev.
(Reading database ... 124663 files and directories currently installed.)
Preparing to unpack .../0-libpq-dev_12.6-0ubuntu0.20.04.1_amd64.deb ...
Unpacking libpq-dev (12.6-0ubuntu0.20.04.1) ...
Selecting previously unselected package libpython2.7:amd64.
Preparing to unpack .../1-libpython2.7_2.7.18-1~20.04.1_amd64.deb ...
Unpacking libpython2.7:amd64 (2.7.18-1~20.04.1) ...
Selecting previously unselected package libpython2.7-dev:amd64.
Preparing to unpack .../2-libpython2.7-dev_2.7.18-1~20.04.1_amd64.deb ...
Unpacking libpython2.7-dev:amd64 (2.7.18-1~20.04.1) ...
Selecting previously unselected package libpython2-dev:amd64.
Preparing to unpack .../3-libpython2-dev_2.7.17-2ubuntu4_amd64.deb ...
Unpacking libpython2-dev:amd64 (2.7.17-2ubuntu4) ...
Selecting previously unselected package python-is-python2.
Preparing to unpack .../4-python-is-python2_2.7.17-4_all.deb ...
Unpacking python-is-python2 (2.7.17-4) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../5-python2.7-dev_2.7.18-1~20.04.1_amd64.deb ...
Unpacking python2.7-dev (2.7.18-1~20.04.1) ...
Selecting previously unselected package python2-dev.
Preparing to unpack .../6-python2-dev_2.7.17-2ubuntu4_amd64.deb ...
Unpacking python2-dev (2.7.17-2ubuntu4) ...
Selecting previously unselected package python-dev-is-python2.
Preparing to unpack .../7-python-dev-is-python2_2.7.17-4_all.deb ...
Unpacking python-dev-is-python2 (2.7.17-4) ...
Setting up libpython2.7:amd64 (2.7.18-1~20.04.1) ...
Setting up libpython2.7-dev:amd64 (2.7.18-1~20.04.1) ...
Setting up libpq-dev (12.6-0ubuntu0.20.04.1) ...
Setting up libpython2-dev:amd64 (2.7.17-2ubuntu4) ...
Setting up python-is-python2 (2.7.17-4) ...
Setting up python2.7-dev (2.7.18-1~20.04.1) ...
Setting up python2-dev (2.7.17-2ubuntu4) ...
Setting up python-dev-is-python2 (2.7.17-4) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.3) ...
root@:/home/odoo/odoo143-8# pip3 install psycopg2
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting psycopg2Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383 kB)|████████████████████████████████| 383 kB 38.0 MB/s
Building wheels for collected packages: psycopg2Building wheel for psycopg2 (setup.py) ... doneCreated wheel for psycopg2: filename=psycopg2-2.8.6-cp38-cp38-linux_x86_64.whl size=505007 sha256=c3cc9533dbce94c712f595abe78d8c55c427a85953202a7efacedc15fb35797cStored in directory: /root/.cache/pip/wheels/ff/bc/64/94aa1ef4380d14bf08bf665d42eaea8e0219dce0ac83738f93
Successfully built psycopg2
Installing collected packages: psycopg2
Successfully installed psycopg2-2.8.6
root@:/home/odoo/odoo143-8#

安装OK

python 安装 psycopg2 报错问题处理相关推荐

  1. python安装报错类型_解决Python安装cryptography报错问题

    解决Python安装cryptography报错问题 错误一: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wst ...

  2. 【已解决】Python安装TensorFlow报错“Consider adding this directory to PATH or, if you prefer to suppress this

    [已解决]Python安装TensorFlow报错"Consider adding this directory to PATH or, if you prefer to suppress ...

  3. python 安装 pyinstaller 报错Preparing wheel metadata ... error

    python 安装 pyinstaller 报错Preparing wheel metadata ... error ERROR: Command errored out with exit stat ...

  4. python psycopg2使用_python3环境安装psycopg2报错

    报错信息如下: ERROR: Command errored out with exit status 1: command: /root/anaconda3/bin/python -c 'impor ...

  5. python安装Pyro报错:SyntaxError: Missing parentheses in call to ‘exec‘

    开门见山,报错的原因就是因为:python2和3的exec方法调用格式不同. 起因如下:我要下载一个python库pyro,这个是一个概率编程的库.所以第一想法当然是: pip install pyr ...

  6. qpython3安装lxml_centos python安装lxml报错

    如题,报错如下,尝试安装了相关的依赖包还是不行 Using cached lxml-3.6.0.tar.gz Building wheels for collected packages: lxml ...

  7. python安装插件报错原因_Sublime Text3 python自动补全问题——Sublime Text3安装Anaconda插件...

    学习python的时候 在编辑器的选择上会有很多选择,我最终还是选择了sublime text3. 相对于其他编辑器,sublime text有以下特性: 插件多,类似GoSublime,Emmet信 ...

  8. python安装robotframework报错_robotframework-autoitlibrary离线安装

    由于AutoItLibrary需要依赖pywin32库.所以要使用AutoItLibrary必须要先安装好pywin32 今天需要在win7 64位系统下安装autoitlibrary库,起初安装好了 ...

  9. python安装robotframework报错_Python3+RIDE+RobotFramework自动化测试框架搭建过程详解

    Python2.7已于2020年1月1日开始停用,之前RF做自动化都是基于Python2的版本. 没办法,跟随时代的脚步,我们也不得不升级以应用新的控件与功能. 升级麻烦,直接全新安装. 一.Pyth ...

最新文章

  1. oracle怎么调报表,集智数据平台报表如何调用Oracle数据存储过程
  2. MongoDB(一):简介
  3. 关于SubSonic3.0插件使用SqlQuery或Select查询时产生的System.NullReferenceException异常修复...
  4. Linux文件大小排序
  5. CSS之【超链接伪类】
  6. 开源工具Arena,数据科学家再也不用为Kubernetes犯难啦!
  7. BIEE入门(一)架构
  8. python读取python源代码文件_python 读写excel文件操作示例【附源码下载】
  9. 算法导论笔记:32字符串匹配算法
  10. “猜你喜欢”是怎么猜中你心思的?
  11. AltiumDesigner16安装教程
  12. 从Oracle迁移到MySQL的各种坑及自救方案
  13. 录制音频文件大小的计算
  14. pycharm2019+破解补丁
  15. 字节跳动高工面试:java高级程序员面试宝典蔡羽豆瓣
  16. 四方、曾经魂牵梦萦的地方
  17. 协作图(Collaboration diagram)——UML之图七
  18. 多表查询时,执行速度耗时太多
  19. WIN二种安装方式UEFI和BIOS方式引导修复
  20. 懂得感恩的人,运气都不会太差

热门文章

  1. 傲慢与偏见。你所不知道的select()——The C10M Problem
  2. [LINUX]linux系统日志
  3. Dolphinscheduler 安装笔记
  4. Firefly RK3399开源板的双目摄像头数据采集方案
  5. 科技英语/专业英语——改错总结【2】
  6. c语言3des算法,3DES算法加解密介绍
  7. 【高并发内存池】第一篇:定长内存池设计
  8. 北京慧点科技有限公司java开发实习生面试过程
  9. 前端百题斩【031】——从渲染流程认识重绘和回流
  10. jquery validate 校验