简体   繁体   English

错误:psycopg2 的构建轮失败

[英]ERROR: Failed building wheel for psycopg2

I've been trying to connect my databse to pgadmin4.我一直在尝试将我的数据库连接到 pgadmin4。 I connected it successfully but now my heroku app returns internal server error.我连接成功,但现在我的 heroku 应用程序返回内部服务器错误。 In order to debug this I do heroku logs -t and it returns ImportError: No module named psycopg2 .为了调试这个我做heroku logs -t它返回ImportError: No module named psycopg2 So I then try to do pip install psycopg2 but I get the following error:所以我然后尝试做pip install psycopg2但我收到以下错误:

Collecting psycopg2
  Using cached psycopg2-2.8.5.tar.gz (380 kB)
Building wheels for collected packages: psycopg2
  Building wheel for psycopg2 (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/Documents/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/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 /private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-wheel-z2s31ha_
       cwd: /private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/psycopg2/
  Complete output (42 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.7
  creating build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/_json.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/extras.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/compat.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/errorcodes.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/tz.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/_range.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/_ipaddress.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/_lru_cache.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/__init__.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/extensions.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/errors.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/sql.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  copying lib/pool.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.macosx-10.15-x86_64-3.7
  creating build/temp.macosx-10.15-x86_64-3.7/psycopg
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DPSYCOPG_VERSION=2.8.5 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120002 -DHAVE_LO64=1 -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include -I/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.15-x86_64-3.7/psycopg/psycopgmodule.o
  In file included from psycopg/psycopgmodule.c:28:
  In file included from ./psycopg/psycopg.h:35:
  In file included from /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include/Python.h:8:
  /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include/pyconfig.h:59:10: fatal error: 'io.h' file not found
  #include <io.h>
           ^~~~~~
  1 error generated.

  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 packages
  required 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 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2
  Running setup.py clean for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
    Running setup.py install for psycopg2 ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/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 /private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-record-3cminrp4/install-record.txt --single-version-externally-managed --compile --install-headers /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include/site/python3.7/psycopg2
         cwd: /private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/psycopg2/
    Complete output (42 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.15-x86_64-3.7
    creating build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/_json.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/extras.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/compat.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/errorcodes.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/tz.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/_range.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/_ipaddress.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/_lru_cache.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/__init__.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/extensions.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/errors.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/sql.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    copying lib/pool.py -> build/lib.macosx-10.15-x86_64-3.7/psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.macosx-10.15-x86_64-3.7
    creating build/temp.macosx-10.15-x86_64-3.7/psycopg
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DPSYCOPG_VERSION=2.8.5 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120002 -DHAVE_LO64=1 -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include -I/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/include/python3.7m -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.15-x86_64-3.7/psycopg/psycopgmodule.o
    In file included from psycopg/psycopgmodule.c:28:
    In file included from ./psycopg/psycopg.h:35:
    In file included from /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include/Python.h:8:
    /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/include/pyconfig.h:59:10: fatal error: 'io.h' file not found
    #include <io.h>
             ^~~~~~
    1 error generated.

    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 packages
    required 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 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/nicolasrizzoehrenbock/Documents/ContactBook/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-install-mpy9u7el/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 /private/var/folders/yj/3jfym00d7r3_f9_jmkrt999r0000gn/T/pip-record-3cminrp4/install-record.txt --single-version-externally-managed --compile --install-headers /Users/Documents/venv/include/site/python3.7/psycopg2 Check the logs for full command output.

I tried doing pip install psycopg2-binary but i have it already installed.我尝试做pip install psycopg2-binary但我已经安装了它。 I also tried in already asked questions but nothing worked.我也尝试了已经提出的问题,但没有任何效果。 Thanks in advance提前致谢

psycopg2-binary is not a dependency of psycopg2 . psycopg2-binary不是psycopg2的依赖项。 It is a replacement.它是一个替代品。

So if psyocpg2 fails to install, just install psycopg2-binary instead.因此,如果psyocpg2无法安装,只需安装psycopg2-binary即可。

The difference boils down to compilation.差异归结为编译。 psycopg2-binary is a pre-compiled binary whereas psycopg2 will be compiled specifically for your system. psycopg2-binary是预编译的二进制文件,而psycopg2将专门为您的系统编译。 It is preferred but if you do not have an appropriate compiler installed then the installation will fail.这是首选,但如果您没有安装适当的编译器,则安装将失败。 In this case you can use the pre-compiled binary psycopg2-binary instead.在这种情况下,您可以改用预编译的二进制psycopg2-binary It is a drop-in replacement (ie you still use import psycopg2 ).它是一个替代品(即您仍然使用import psycopg2 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM