cffi 的构建和安装失败

(venv) ~/P/PickleballMaps ❯❯❯ pip install cffi==1.11.0                                                                                                                                                                                                                   ✘ 1 
Collecting cffi==1.11.0
  Downloading cffi-1.11.0.tar.gz (434 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 434.3/434.3 KB 5.6 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Requirement already satisfied: pycparser in ./venv/lib/python3.8/site-packages (from cffi==1.11.0) (2.18)
Building wheels for collected packages: cffi
  Building wheel for cffi (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [134 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-3.8
      creating build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/backend_ctypes.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/error.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/setuptools_ext.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/cffi_opcode.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/vengine_gen.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/model.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/ffiplatform.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/api.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/vengine_cpy.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/commontypes.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/lock.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/recompiler.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/cparser.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/verifier.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_cffi_include.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/parse_c_type.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_embedding.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_cffi_errors.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      running build_ext
      building '_cffi_backend' extension
      creating build/temp.macosx-10.9-x86_64-3.8
      creating build/temp.macosx-10.9-x86_64-3.8/c
      gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi -I/Users/johnvergo/PycharmProjects/PickleballMaps/venv/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c c/_cffi_backend.c -o build/temp.macosx-10.9-x86_64-3.8/c/_cffi_backend.o
      In file included from c/_cffi_backend.c:319:
      c/minibuffer.h:66:9: warning: 'PyObject_AsReadBuffer' is deprecated [-Wdeprecated-declarations]
          if (PyObject_AsReadBuffer(other, &buffer, &buffer_len) < 0)
              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/abstract.h:336:1: note: 'PyObject_AsReadBuffer' has been explicitly marked deprecated here
      Py_DEPRECATED(3.0)
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      In file included from c/_cffi_backend.c:322:
      c/file_emulator.h:54:14: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              mode = PyText_AsUTF8(ob_mode);
                   ^ ~~~~~~~~~~~~~~~~~~~~~~
      c/_cffi_backend.c:2678:10: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          text = PyText_AsUTF8(attr);
               ^ ~~~~~~~~~~~~~~~~~~~
      c/_cffi_backend.c:4748:28: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                      do_align = PyText_GetSize(fname) > 0;
                                 ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:4786:17: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                  if (PyText_GetSize(fname) == 0 &&
                      ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:4858:21: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                      if (PyText_GetSize(fname) > 0) {
                          ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:5817:9: warning: 'ffi_prep_closure' is deprecated [-Wdeprecated-declarations]
          if (ffi_prep_closure(closure, &cif_descr->cif,
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi/ffi.h:348:18: note: 'ffi_prep_closure' has been explicitly marked deprecated here
        __attribute__((deprecated))
                       ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:15:
      c/ffi_obj.c:191:19: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  char *input_text = PyText_AS_UTF8(arg);
                        ^            ~~~~~~~~~~~~~~~~~~~
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:17:
      c/lib_obj.c:130:11: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          char *libname = PyText_AS_UTF8(lib->l_libname);
                ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      c/lib_obj.c:209:11: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          char *s = PyText_AsUTF8(name);
                ^   ~~~~~~~~~~~~~~~~~~~
      c/lib_obj.c:507:7: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          p = PyText_AsUTF8(name);
            ^ ~~~~~~~~~~~~~~~~~~~
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:20:30: error: incomplete definition of type 'struct _is'
          builtins = tstate->interp->builtins;
                     ~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:73:11: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              s = PyText_AsUTF8(name);
                ^ ~~~~~~~~~~~~~~~~~~~
      c/call_python.c:160:39: error: incomplete definition of type 'struct _is'
          new1 = PyThreadState_GET()->interp->modules;
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:249:63: error: incomplete definition of type 'struct _is'
              if (externpy->reserved1 != PyThreadState_GET()->interp->modules) {
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      12 warnings and 3 errors generated.
      error: command 'gcc' failed with exit status 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cffi
  Running setup.py clean for cffi
Failed to build cffi
Installing collected packages: cffi
  Attempting uninstall: cffi
    Found existing installation: cffi 1.15.0
    Not uninstalling cffi at /Users/johnvergo/Library/Python/3.8/lib/python/site-packages, outside environment /Users/johnvergo/PycharmProjects/PickleballMaps/venv
    Can't uninstall 'cffi'. No files were found to uninstall.
  Running setup.py install for cffi ... error
  error: subprocess-exited-with-error

  × Running setup.py install for cffi did not run successfully.
  │ exit code: 1
  ╰─> [134 lines of output]
      running install
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-3.8
      creating build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/backend_ctypes.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/error.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/setuptools_ext.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/cffi_opcode.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/vengine_gen.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/model.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/ffiplatform.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/api.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/vengine_cpy.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/commontypes.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/lock.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/recompiler.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/cparser.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/verifier.py -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_cffi_include.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/parse_c_type.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_embedding.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      copying cffi/_cffi_errors.h -> build/lib.macosx-10.9-x86_64-3.8/cffi
      running build_ext
      building '_cffi_backend' extension
      creating build/temp.macosx-10.9-x86_64-3.8
      creating build/temp.macosx-10.9-x86_64-3.8/c
      gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi -I/Users/johnvergo/PycharmProjects/PickleballMaps/venv/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c c/_cffi_backend.c -o build/temp.macosx-10.9-x86_64-3.8/c/_cffi_backend.o
      In file included from c/_cffi_backend.c:319:
      c/minibuffer.h:66:9: warning: 'PyObject_AsReadBuffer' is deprecated [-Wdeprecated-declarations]
          if (PyObject_AsReadBuffer(other, &buffer, &buffer_len) < 0)
              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/abstract.h:336:1: note: 'PyObject_AsReadBuffer' has been explicitly marked deprecated here
      Py_DEPRECATED(3.0)
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      In file included from c/_cffi_backend.c:322:
      c/file_emulator.h:54:14: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              mode = PyText_AsUTF8(ob_mode);
                   ^ ~~~~~~~~~~~~~~~~~~~~~~
      c/_cffi_backend.c:2678:10: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          text = PyText_AsUTF8(attr);
               ^ ~~~~~~~~~~~~~~~~~~~
      c/_cffi_backend.c:4748:28: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                      do_align = PyText_GetSize(fname) > 0;
                                 ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:4786:17: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                  if (PyText_GetSize(fname) == 0 &&
                      ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:4858:21: warning: 'PyUnicode_GetSize' is deprecated [-Wdeprecated-declarations]
                      if (PyText_GetSize(fname) > 0) {
                          ^
      c/_cffi_backend.c:104:25: note: expanded from macro 'PyText_GetSize'
      # define PyText_GetSize PyUnicode_GetSize
                              ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/unicodeobject.h:177:1: note: 'PyUnicode_GetSize' has been explicitly marked deprecated here
      Py_DEPRECATED(3.3) PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
      ^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
      #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                           ^
      c/_cffi_backend.c:5817:9: warning: 'ffi_prep_closure' is deprecated [-Wdeprecated-declarations]
          if (ffi_prep_closure(closure, &cif_descr->cif,
              ^
      /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi/ffi.h:348:18: note: 'ffi_prep_closure' has been explicitly marked deprecated here
        __attribute__((deprecated))
                       ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:15:
      c/ffi_obj.c:191:19: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  char *input_text = PyText_AS_UTF8(arg);
                        ^            ~~~~~~~~~~~~~~~~~~~
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:17:
      c/lib_obj.c:130:11: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          char *libname = PyText_AS_UTF8(lib->l_libname);
                ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      c/lib_obj.c:209:11: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          char *s = PyText_AsUTF8(name);
                ^   ~~~~~~~~~~~~~~~~~~~
      c/lib_obj.c:507:7: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          p = PyText_AsUTF8(name);
            ^ ~~~~~~~~~~~~~~~~~~~
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:20:30: error: incomplete definition of type 'struct _is'
          builtins = tstate->interp->builtins;
                     ~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:73:11: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
              s = PyText_AsUTF8(name);
                ^ ~~~~~~~~~~~~~~~~~~~
      c/call_python.c:160:39: error: incomplete definition of type 'struct _is'
          new1 = PyThreadState_GET()->interp->modules;
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      In file included from c/_cffi_backend.c:7276:
      In file included from c/cffi1_module.c:20:
      c/call_python.c:249:63: error: incomplete definition of type 'struct _is'
              if (externpy->reserved1 != PyThreadState_GET()->interp->modules) {
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
      /Library/Frameworks/Python.framework/Versions/3.8/include/python3.8/pystate.h:20:8: note: forward declaration of 'struct _is'
      struct _is;
             ^
      12 warnings and 3 errors generated.
      error: command 'gcc' failed with exit status 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Can't roll back cffi; was not uninstalled
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> cffi

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

我还尝试卸载 cffi 并收到此消息:

pip 卸载 cffi
✘ 1 找到现有安装:cffi 1.15.0 未在 /Users/johnvergo/Library/Python/3.8/lib/python/site-packages 卸载 cffi,外部环境 /Users/johnvergo/PycharmProjects/PickleballMaps/venv 无法卸载'cffi'。找不到要卸载的文件。

stack overflow Build and install of cffi fails
原文答案

答案:

作者头像

看到输出中有很多提到 deprecated 并且 cffi==1.11 仅在 python 3.6 之前得到官方支持,我敢打赌唯一的问题是 cffi==1.11 与 python 3.8 不兼容.

在这种情况下,我会尝试使用 python 3.6。那么应该不需要编译,因为 pypi 上也有该版本的 whl 文件

作者头像

我有一个类似的问题,需要由 Adob​​e 为 pdfservices-sdk 安装 cffi。

原来的解决方案是2倍

  1. 确保完整的 C++/C 开发工具并确保它们位于 PATH 环境变量中。

  2. 让python 3.7.9 成为python 的实例,就像上面的评论者所说的那样,cffi 与较新版本的python 不兼容。