Skip to content

pip install cffi fails on MSYS2 #159

Closed

Description

@tieneupin

Hi there! I am encountering issues with pip installing cffi in an MSYS2 environment (UCRT64, in my case).

Running pip install cffi returns the following error:

Collecting cffi
  Using cached cffi-1.17.1.tar.gz (516 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting pycparser (from cffi)
  Using cached pycparser-2.22-py3-none-any.whl.metadata (943 bytes)
Using cached pycparser-2.22-py3-none-any.whl (117 kB)
Building wheels for collected packages: cffi
  Building wheel for cffi (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for cffi (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [68 lines of output]
      _configtest.c:2:2: error: #error "not MSVC"
          2 | #error "not MSVC"
            |  ^~~~~
      Note: will not use '__thread' in the C code
      ***** The above error message can be safely ignored.

      C:/msys64/tmp/pip-build-env-0lk6z3p_/overlay/lib/python3.12/site-packages/setuptools/dist.py:7
59: SetuptoolsDeprecationWarning: License classifiers are deprecated.
      !!

              ********************************************************************************
              Please consider removing the following classifiers in favor of a SPDX license expressi
on:

              License :: OSI Approved :: MIT License

              See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for
details.
              ********************************************************************************

      !!
        self._finalize_license_expression()
      running bdist_wheel
      running build
      running build_py
      creating build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/api.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/backend_ctypes.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/cffi_opcode.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/commontypes.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/cparser.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/error.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/ffiplatform.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/lock.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/model.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/pkgconfig.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/recompiler.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/setuptools_ext.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/vengine_cpy.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/vengine_gen.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/verifier.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/_imp_emulation.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/_shimmed_dist_utils.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/__init__.py -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/_cffi_include.h -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/parse_c_type.h -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/_embedding.h -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      copying src/cffi/_cffi_errors.h -> build/lib.mingw_x86_64_ucrt_gnu-cpython-312/cffi
      running build_ext
      building '_cffi_backend' extension
      creating build/temp.mingw_x86_64_ucrt_gnu-cpython-312/src/c
      gcc -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -march=nocona -msahf -mtune=gene
ric -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wp,-D__USE_MINGW_ANSI_STDIO=1 -O3 -m
arch=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wp,-D_
_USE_MINGW_ANSI_STDIO=1 -O3 -DFFI_BUILDING=1 -IC:/msys64/home/username/envs/cffi-test/include -IC:/m
sys64/ucrt64/include/python3.12 -c src/c/_cffi_backend.c -o build/temp.mingw_x86_64_ucrt_gnu-cpython
-312/src/c/_cffi_backend.o
      src/c/_cffi_backend.c: In function 'b_do_dlopen':
      src/c/_cffi_backend.c:4568:40: error: passing argument 1 of 'PyUnicode_AsWideChar' from incomp
atible pointer type [-Wincompatible-pointer-types]
       4568 |             sz1 = PyUnicode_AsWideChar((PyUnicodeObject *)filename_unicode,
            |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            |                                        |
            |                                        PyUnicodeObject *
      In file included from C:/msys64/ucrt64/include/python3.12/Python.h:51,
                       from src/c/_cffi_backend.c:2:
      C:/msys64/ucrt64/include/python3.12/unicodeobject.h:286:15: note: expected 'PyObject *' {aka '
struct _object *'} but argument is of type 'PyUnicodeObject *'
        286 |     PyObject *unicode,          /* Unicode object */
            |     ~~~~~~~~~~^~~~~~~
      src/c/_cffi_backend.c:4579:22: warning: 'Py_FileSystemDefaultEncoding' is deprecated [-Wdeprec
ated-declarations]
       4579 |                      Py_FileSystemDefaultEncoding, &filename_or_null, &flags))
            |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      In file included from C:/msys64/ucrt64/include/python3.12/Python.h:72:
      C:/msys64/ucrt64/include/python3.12/fileobject.h:22:46: note: declared here
         22 | Py_DEPRECATED(3.12) PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
            |                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      error: command 'C:\\msys64\\ucrt64\\bin/gcc.EXE' failed with exit code 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
Failed to build cffi
ERROR: Failed to build installable wheels for some pyproject.toml based projects (cffi)

Additionally, it looks like setuptools has removed distutils as of Python 3.12 (link), which is what MSYS2 ships by default now. As such, previous workarounds to installing cffi on MSYS2 that involve using SETUPTOOLS_USE_DISTUTILS=stdlib pip install cffi will no longer work (comment from Issue #90).

While it's possible to download and install MSYS2's own compilation of cffi, that one is installed as a system-wide package, and unless one knows how to rearrange and set up the files, it's not suited for working with virtual Python environments.

Would this be an issue your team would consider looking into and addressing going forwards?

Activity

  1. arigo commented on Mar 27, 2025

    @arigo
    Contributor

    This has been fixed already in 69efd78, but not released yet for some reason. @nitzmahone?

  2. tieneupin commented on Mar 31, 2025

    @tieneupin
    Author

    @arigo , for what it's worth, at least that is the only line that needs changing when I pip download cffi on v1.17.1 and edit the code. pip install . then works smoothly after that.

    Hopefully that commit will make its way into the next version of cffi soon! 🙏

  3. nitzmahone commented on Apr 2, 2025

    @nitzmahone
    Member

    Hrm, I might need to twiddle some notification settings, because I never saw any of those PRs getting filed or merged.

    I've been doing some local spot-testing on 3.14 alphas, but with beta coming soon, there'll be a bunch of housekeeping to be done in the next few weeks. Kicking out a 1.17.2 as part of that seems like a good idea.

  4. tiararodney commented on Apr 5, 2025

    @tiararodney

    @arigo , for what it's worth, at least that is the only line that needs changing when I pip download cffi on v1.17.1 and edit the code. pip install . then works smoothly after that.

    Hopefully that commit will make its way into the next version of cffi soon! 🙏

    Hi. You could also install the package via git and checkout the main branch. Afterwards, install the package dependent upon it with --no-build-isolation, to force usage of the locally present dependency instead of fetching it via pypi.

    # @main does not necessarily have to be supplied
    .venv/bin/pip install git+https://github.com/python-cffi/cffi.git@main
    .venv/bin/pip install --no-build-isolation <your-package>

    You could also explicitly define it that way as a dependency in requirements.txt.

  5. tieneupin commented on Apr 6, 2025

    @tieneupin
    Author

    @ByteB4rb1e , thanks for your suggestion on alternative ways to download and install cffi.

    Our PCs are network-restricted, so any downloads that we make will have to go through API endpoints that we ourselves have manually set up to serve the desired items. We have one set up for PyPI already, so having the package with the fix released on PyPI would make things really convenient. Writing such a mirror to the GitHub would be doable, but would just mean additional work for a fix that will hopefully be made available on PyPI soon.

    From the looks of it, a new cffi patch with the necessary fixes is in the works, so I will look forward to that.

  6. rost0031 commented on Aug 1, 2025

    @rost0031

    I just did a fresh install of MinGW on win10 and I am having this same issue. All the upstream version of cffi don't install and the one from this github gives an error attempting to link to some windows intrinsic:

      gcc -shared -Wl,--enable-auto-image-base -Wno-error=implicit-function-declaration -Wno-error=incom
    patible-pointer-types -Wno-error=int-conversion -s build/temp.mingw_x86_64_msvcrt_gnu-cpython-312/sr
    c/c/_cffi_backend.o build/temp.mingw_x86_64_msvcrt_gnu-cpython-312/src/c/_cffi_backend.cp312-mingw_x
    86_64_msvcrt_gnu.def -LC:/msys64/mingw64/lib/../lib -LC:/msys64/mingw64/lib -lffi -lpython3.12 -o bu
    ild/lib.mingw_x86_64_msvcrt_gnu-cpython-312/_cffi_backend.cp312-mingw_x86_64_msvcrt_gnu.pyd
      C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/../../../../x86_64-w64-mingw32/bin/ld.e
    xe: build/temp.mingw_x86_64_msvcrt_gnu-cpython-312/src/c/_cffi_backend.o:_cffi_backend.:(.text+0x176
    2): undefined reference to `_InterlockedExchange8'
      collect2.exe: error: ld returned 1 exit status
      error: command 'C:\\msys64\\mingw64\\bin/gcc.EXE' failed with exit code 1
      error: subprocess-exited-with-error
    

    I was able to finally install 1.17.1 with the following:

    export CFLAGS="-Wno-error=implicit-function-declaration -Wno-error=incompatible-pointer-types -Wno-error=int-conversion"; python -m pip -v install cffi

  7. added a commit that references this issue on Sep 9, 2025
  8. lazka commented on Sep 9, 2025

    @lazka
    Contributor

    See #198

  9. added a commit that references this issue on Sep 11, 2025
  10. mattip commented on Feb 4, 2026

    @mattip
    Contributor

    Closed by #198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions