Repository navigation
pip install cffi fails on MSYS2 #159
Description
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
arigo commentedon Mar 27, 2025
This has been fixed already in 69efd78, but not released yet for some reason. @nitzmahone?
tieneupin commentedon Mar 31, 2025
@arigo , for what it's worth, at least that is the only line that needs changing when I
pip download cffion 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
cffisoon! 🙏nitzmahone commentedon Apr 2, 2025
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.
tiararodney commentedon Apr 5, 2025
Hi. You could also install the package via git and checkout the
mainbranch. 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.You could also explicitly define it that way as a dependency in
requirements.txt.tieneupin commentedon Apr 6, 2025
@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
cffipatch with the necessary fixes is in the works, so I will look forward to that.rost0031 commentedon Aug 1, 2025
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:
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 cffiFix mingw build re atomic functions
lazka commentedon Sep 9, 2025
See #198
Fix mingw build re atomic functions (#198)
mattip commentedon Feb 4, 2026
Closed by #198