python 安装 psycopg2 报错问题处理

短命女 2022-10-15 12:48 1177阅读 0赞

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

  1. pip3 install psycopg2
  2. Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
  3. Collecting psycopg2
  4. Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383 kB)
  5. |████████████████████████████████| 383 kB 14.7 MB/s
  6. Building wheels for collected packages: psycopg2
  7. Building wheel for psycopg2 (setup.py) ... error
  8. ERROR: Command errored out with exit status 1:
  9. 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-b8tz2p9a
  10. cwd: /tmp/pip-install-6gdzdzy9/psycopg2/
  11. Complete output (40 lines):
  12. running bdist_wheel
  13. running build
  14. running build_py
  15. creating build
  16. creating build/lib.linux-x86_64-3.8
  17. creating build/lib.linux-x86_64-3.8/psycopg2
  18. copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
  19. copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
  20. copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
  21. copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
  22. copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
  23. copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2
  24. copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
  25. copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
  26. copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
  27. copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
  28. copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
  29. copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2
  30. copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
  31. running build_ext
  32. building 'psycopg2._psycopg' extension
  33. creating build/temp.linux-x86_64-3.8
  34. creating build/temp.linux-x86_64-3.8/psycopg
  35. x86_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-statement
  36. In file included from psycopg/psycopgmodule.c:28:
  37. ./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
  38. 36 | #include <libpq-fe.h>
  39. | ^~~~~~~~~~~~
  40. compilation terminated.
  41. It appears you are missing some prerequisite to build the package from source.
  42. You may install a binary package by installing 'psycopg2-binary' from PyPI.
  43. If you want to install psycopg2 from source, please install the packages
  44. required for the build and try again.
  45. For further information please check the 'doc/src/install.rst' file (also at
  46. <https://www.psycopg.org/docs/install.html>).
  47. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  48. ----------------------------------------
  49. ERROR: Failed building wheel for psycopg2
  50. Running setup.py clean for psycopg2
  51. Failed to build psycopg2
  52. Installing collected packages: psycopg2
  53. Running setup.py install for psycopg2 ... error
  54. ERROR: Command errored out with exit status 1:
  55. 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/psycopg2
  56. cwd: /tmp/pip-install-6gdzdzy9/psycopg2/
  57. Complete output (40 lines):
  58. running install
  59. running build
  60. running build_py
  61. creating build
  62. creating build/lib.linux-x86_64-3.8
  63. creating build/lib.linux-x86_64-3.8/psycopg2
  64. copying lib/errors.py -> build/lib.linux-x86_64-3.8/psycopg2
  65. copying lib/pool.py -> build/lib.linux-x86_64-3.8/psycopg2
  66. copying lib/sql.py -> build/lib.linux-x86_64-3.8/psycopg2
  67. copying lib/tz.py -> build/lib.linux-x86_64-3.8/psycopg2
  68. copying lib/extras.py -> build/lib.linux-x86_64-3.8/psycopg2
  69. copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.8/psycopg2
  70. copying lib/_json.py -> build/lib.linux-x86_64-3.8/psycopg2
  71. copying lib/_range.py -> build/lib.linux-x86_64-3.8/psycopg2
  72. copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.8/psycopg2
  73. copying lib/errorcodes.py -> build/lib.linux-x86_64-3.8/psycopg2
  74. copying lib/extensions.py -> build/lib.linux-x86_64-3.8/psycopg2
  75. copying lib/compat.py -> build/lib.linux-x86_64-3.8/psycopg2
  76. copying lib/__init__.py -> build/lib.linux-x86_64-3.8/psycopg2
  77. running build_ext
  78. building 'psycopg2._psycopg' extension
  79. creating build/temp.linux-x86_64-3.8
  80. creating build/temp.linux-x86_64-3.8/psycopg
  81. x86_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-statement
  82. In file included from psycopg/psycopgmodule.c:28:
  83. ./psycopg/psycopg.h:36:10: fatal error: libpq-fe.h: No such file or directory
  84. 36 | #include <libpq-fe.h>
  85. | ^~~~~~~~~~~~
  86. compilation terminated.
  87. It appears you are missing some prerequisite to build the package from source.
  88. You may install a binary package by installing 'psycopg2-binary' from PyPI.
  89. If you want to install psycopg2 from source, please install the packages
  90. required for the build and try again.
  91. For further information please check the 'doc/src/install.rst' file (also at
  92. <https://www.psycopg.org/docs/install.html>).
  93. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  94. ----------------------------------------
  95. 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.

原因是因为缺少安装依赖

安装如下依赖:

  1. sudo apt-get install libpq-dev python-dev

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

  1. sudo apt-get install libpq-dev python-dev
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Note, selecting 'python-dev-is-python2' instead of 'python-dev'
  6. The following additional packages will be installed:
  7. libpython2-dev libpython2.7 libpython2.7-dev python-is-python2 python2-dev python2.7-dev
  8. Suggested packages:
  9. postgresql-doc-12
  10. The following NEW packages will be installed:
  11. libpq-dev libpython2-dev libpython2.7 libpython2.7-dev python-dev-is-python2 python-is-python2 python2-dev python2.7-dev
  12. 0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
  13. Need to get 3,948 kB of archives.
  14. After this operation, 18.3 MB of additional disk space will be used.
  15. Do you want to continue? [Y/n] y
  16. Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu focal-updates/main amd64 libpq-dev amd64 12.6-0ubuntu0.20.04.1 [136 kB]
  17. 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]
  18. 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]
  19. Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 libpython2-dev amd64 2.7.17-2ubuntu4 [7,140 B]
  20. Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python-is-python2 all 2.7.17-4 [2,496 B]
  21. 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]
  22. Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python2-dev amd64 2.7.17-2ubuntu4 [1,268 B]
  23. Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu focal/universe amd64 python-dev-is-python2 all 2.7.17-4 [1,396 B]
  24. Fetched 3,948 kB in 1s (7,438 kB/s)
  25. Selecting previously unselected package libpq-dev.
  26. (Reading database ... 124663 files and directories currently installed.)
  27. Preparing to unpack .../0-libpq-dev_12.6-0ubuntu0.20.04.1_amd64.deb ...
  28. Unpacking libpq-dev (12.6-0ubuntu0.20.04.1) ...
  29. Selecting previously unselected package libpython2.7:amd64.
  30. Preparing to unpack .../1-libpython2.7_2.7.18-1~20.04.1_amd64.deb ...
  31. Unpacking libpython2.7:amd64 (2.7.18-1~20.04.1) ...
  32. Selecting previously unselected package libpython2.7-dev:amd64.
  33. Preparing to unpack .../2-libpython2.7-dev_2.7.18-1~20.04.1_amd64.deb ...
  34. Unpacking libpython2.7-dev:amd64 (2.7.18-1~20.04.1) ...
  35. Selecting previously unselected package libpython2-dev:amd64.
  36. Preparing to unpack .../3-libpython2-dev_2.7.17-2ubuntu4_amd64.deb ...
  37. Unpacking libpython2-dev:amd64 (2.7.17-2ubuntu4) ...
  38. Selecting previously unselected package python-is-python2.
  39. Preparing to unpack .../4-python-is-python2_2.7.17-4_all.deb ...
  40. Unpacking python-is-python2 (2.7.17-4) ...
  41. Selecting previously unselected package python2.7-dev.
  42. Preparing to unpack .../5-python2.7-dev_2.7.18-1~20.04.1_amd64.deb ...
  43. Unpacking python2.7-dev (2.7.18-1~20.04.1) ...
  44. Selecting previously unselected package python2-dev.
  45. Preparing to unpack .../6-python2-dev_2.7.17-2ubuntu4_amd64.deb ...
  46. Unpacking python2-dev (2.7.17-2ubuntu4) ...
  47. Selecting previously unselected package python-dev-is-python2.
  48. Preparing to unpack .../7-python-dev-is-python2_2.7.17-4_all.deb ...
  49. Unpacking python-dev-is-python2 (2.7.17-4) ...
  50. Setting up libpython2.7:amd64 (2.7.18-1~20.04.1) ...
  51. Setting up libpython2.7-dev:amd64 (2.7.18-1~20.04.1) ...
  52. Setting up libpq-dev (12.6-0ubuntu0.20.04.1) ...
  53. Setting up libpython2-dev:amd64 (2.7.17-2ubuntu4) ...
  54. Setting up python-is-python2 (2.7.17-4) ...
  55. Setting up python2.7-dev (2.7.18-1~20.04.1) ...
  56. Setting up python2-dev (2.7.17-2ubuntu4) ...
  57. Setting up python-dev-is-python2 (2.7.17-4) ...
  58. Processing triggers for man-db (2.9.1-1) ...
  59. Processing triggers for libc-bin (2.31-0ubuntu9.3) ...
  60. root@:/home/odoo/odoo143-8# pip3 install psycopg2
  61. Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
  62. Collecting psycopg2
  63. Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz (383 kB)
  64. |████████████████████████████████| 383 kB 38.0 MB/s
  65. Building wheels for collected packages: psycopg2
  66. Building wheel for psycopg2 (setup.py) ... done
  67. Created wheel for psycopg2: filename=psycopg2-2.8.6-cp38-cp38-linux_x86_64.whl size=505007 sha256=c3cc9533dbce94c712f595abe78d8c55c427a85953202a7efacedc15fb35797c
  68. Stored in directory: /root/.cache/pip/wheels/ff/bc/64/94aa1ef4380d14bf08bf665d42eaea8e0219dce0ac83738f93
  69. Successfully built psycopg2
  70. Installing collected packages: psycopg2
  71. Successfully installed psycopg2-2.8.6
  72. root@:/home/odoo/odoo143-8#

安装OK

发表评论

表情:
评论列表 (有 0 条评论,1177人围观)

还没有评论,来说两句吧...

相关阅读