Skip to content

Failed using the clang2py command on windows - clang not found error #144

@qaxntl

Description

@qaxntl

Quite new to this, so bare with me!

Trying to wrap a header + dll file to python code on Windows 11 using miniconda.
I made a new conda environment and activated it.
I installed clang via conda install clang (installed version 14.0.6).
Then, I cloned the repo from github.
Then I installed via pip install . clang==14 (Also tried pip install ctypeslib2 clang==14).

Either way I install ctypeslib, I get this error when I run clang2py -o my_lib.py -l my_lib.dll my_lib.h:

C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\ctypeslib\__init__.py:112: RuntimeWarning: Could not find the clang library. please install llvm libclang
  warnings.warn("Could not find the clang library. please install llvm libclang", RuntimeWarning)
Traceback (most recent call last):
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\clang\cindex.py", line 4174, in get_cindex_library
    library = cdll.LoadLibrary(self.get_filename())
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\ctypes\__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\ctypes\__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'libclang.dll' (or one of its dependencies). Try using the full path with constructor syntax.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\[username]\.conda\envs\ctypeslib\Scripts\clang2py.exe\__main__.py", line 7, in <module>
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\ctypeslib\clang2py.py", line 320, in main
    parser = _make_parser(cfg)
             ^^^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\ctypeslib\clang2py.py", line 267, in _make_parser
    parser.add_argument("-V", "--version", action="version", version=version_string())
                                                                     ^^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\ctypeslib\clang2py.py", line 263, in version_string
    f"{ctypeslib.__version__} python-clang:{clang_py_version()} clang:{clang_version()} " \
                                                                       ^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\ctypeslib\__init__.py", line 57, in clang_version
    get_version = cindex.conf.get_cindex_library().clang_getClangVersion
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[username]\.conda\envs\ctypeslib\Lib\site-packages\clang\cindex.py", line 4179, in get_cindex_library
    raise LibclangError(msg)
clang.cindex.LibclangError: Could not find module 'libclang.dll' (or one of its dependencies). Try using the full path with constructor syntax.. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().

I do not understand the error's suggestion in the context of running this command from the command line. Could you please give me any suggestions on how to solve this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions