Skip to content

cffi.FFI().dlopen gives error 0x7e on Windows #64

Description

@Wainberg

Opening the DLL for the R programming language fails with CFFI on Windows on my machine:

>>> import cffi
>>> dll = 'C:\\Users\\Wainberg\\miniforge3\\lib\\R\\bin\\x64\\R.dll'
>>> cffi.FFI().dlopen(dll)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Wainberg\miniforge3\Lib\site-packages\cffi\api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Wainberg\miniforge3\Lib\site-packages\cffi\api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Wainberg\miniforge3\Lib\site-packages\cffi\api.py", line 828, in _load_backend_lib
    return backend.load_library(path, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: cannot load library 'C:\Users\Wainberg\miniforge3\lib\R\bin\x64\R.dll': error 0x7e

But opening the same DLL with ctypes first "magically" makes it open with CFFI as well (note: import cffi is not enough, you have to call ctypes.CDLL(dll) as well):

>>> import ctypes
>>> import cffi
>>> dll = 'C:\\Users\\Wainberg\\miniforge3\\lib\\R\\bin\\x64\\R.dll'
>>> ctypes.CDLL(dll)
<CDLL 'C:\Users\Wainberg\miniforge3\lib\R\bin\x64\R.dll', handle 6c700000 at 0x16358ac1460>
>>> cffi.FFI().dlopen(dll)
<cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x000001635A832EA0>

I am using the base environment of Miniforge (https://github.com/conda-forge/miniforge) for this, but I get the same 0x7e error on my system Python installation. Although there, ctypes.CDLL() also gives an error:

>>> ctypes.CDLL(dll)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\ctypes\__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'C:\Users\Wainberg\miniforge3\lib\R\bin\x64\R.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Using ctypes.util.find_library(dll) doesn't help:

>>> dll
'C:\\Users\\Wainberg\\miniforge3\\lib\\R\\bin\\x64\\R.dll'
>>> ctypes.util.find_library(dll)
'C:\\Users\\Wainberg\\miniforge3\\lib\\R\\bin\\x64\\R.dll'

Activity

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