python-cffi/cffi

Unable to install CFFI 1.16 on MSYS2 MINGW64 using pip (24.1) and python (3.11.9)

Closed this issue · 5 comments

Description

I am currently attempting to install CFFI on my Windows machine running MSYS2 MINGW64 using the terminal command pip install cffi.

System and Versions

OS: Windows 11, MSYS2 MINGW64
Python: 3.11.9
Pip: 24.1
CFFI: 1.16, 1.15.1, 1.15 (versions with which I could reproduce this error)

However, I get the following error:

Collecting cffi
  Using cached cffi-1.16.0.tar.gz (512 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      Traceback (most recent call last):
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/mingw64/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 327, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 297, in _get_build_requires
          self.run_setup()
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 313, in run_setup
          exec(code, locals())
        File "<string>", line 126, in <module>
        File "<string>", line 105, in uses_msvc
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/config.py", line 220, in try_compile
          self._compile(body, headers, include_dirs, lang)
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/config.py", line 132, in _compile
          self.compiler.compile([src], include_dirs=include_dirs)
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/_distutils/_msvccompiler.py", line 343, in compile
          self.initialize()
        File "C:/msys64/tmp/pip-build-env-hyndckce/overlay/lib/python3.11/site-packages/setuptools/_distutils/_msvccompiler.py", line 246, in initialize
          raise DistutilsPlatformError(
      distutils.errors.DistutilsPlatformError: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')

Discussion from #21 did not seem to yield similar results to those in that thread. For example, running pip install --no-build-isolation cffi does not make any difference. Additionally, I get the same error running both pip install cffi==1.15.1 and pip install cffi==1.15.

Furthermore, solutions to similar issues in this Stack Overflow thread did not seem to work either. Specifically, using SETUPTOOLS_USE_DISTUTILS=stdlib.

Any help or insights would be greatly appreciated!

I made some progress here, when I run export SETUPTOOLS_USE_DISTUTILS=stdlib and then python3 -m pip install cffi, I get the following outputs.

<string>:69: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
_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.

I believe that this error is ignored thanks to the export SETUPTOOLS_USE_DISTUTILS=stdlib. However, this is followed by...

building '_cffi_backend' extension
      creating build/temp.mingw_x86_64-3.11
      creating build/temp.mingw_x86_64-3.11/src
      creating build/temp.mingw_x86_64-3.11/src/c
      gcc -DNDEBUG -g -fwrapv -O3 -Wall -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong -O3 -DFFI_BUILDING=1 -IC:/msys64/mingw64/include/python3.11 -c src/c/_cffi_backend.c -o build/temp.mingw_x86_64-3.11/src/c/_cffi_backend.o
      src/c/_cffi_backend.c: In function 'b_do_dlopen':
      src/c/_cffi_backend.c:4521:40: error: passing argument 1 of 'PyUnicode_AsWideChar' from incompatible pointer type [-Wincompatible-pointer-types]
       4521 |             sz1 = PyUnicode_AsWideChar((PyUnicodeObject *)filename_unicode,
            |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            |                                        |
            |                                        PyUnicodeObject *
      In file included from C:/msys64/mingw64/include/python3.11/Python.h:51,
                       from src/c/_cffi_backend.c:2:
      C:/msys64/mingw64/include/python3.11/unicodeobject.h:299:15: note: expected 'PyObject *' {aka 'struct _object *'} but argument is of type 'PyUnicodeObject *'
        299 |     PyObject *unicode,          /* Unicode object */
            |     ~~~~~~~~~~^~~~~~~
      error: command 'C:\\msys64\\mingw64\\bin/gcc.exe' failed with exit code 1

A colleague helped me to solve the issue. Initially, this issue was a result of trying to install the cryptography library. Since cffi is a dependency, its subsequent installation was failing.

It looks like MSYS2 has a specific Python cryptography package that can be installed for this situation as pacman -Sy --needed mingw-w64-x86_64-python3-cryptography.

After I installed this package, the cryptography package worked fine. However, I'll leave this issue open for now as I don't think the issue wasn't directly resolved with cffi. I

Thanks for the report, this looks like a superficial error easily fixed (see PR #91).

Can this issue be closed or is there a remaining TODO?

Yep, closing as completed since it's merged- the change will likely be included in 1.17.1