Why can't this python script find libclang dll?

I would like to start by using libclang with Python . I am trying to get a sample code ( http://www.altdevblogaday.com/2014/03/05/implementing-a-code-generator-with-libclang/ ) for working with Windows , here is the part of the code I'm trying to run:

#!/usr/bin/python # vim: set fileencoding=utf-8 import sys import os import clang.cindex import itertools ... print("Setting clang path") # I tried multiple variations. Libclang is correctly installed in the specified location. #clang.cindex.Config.set_library_path('C:/Program Files (x86)/LLVM/bin') #clang.cindex.Config.set_library_path('C:/Program Files (x86)/LLVM/bin/libclang.dll') # I also tried moving the dll into the Python installation folder. clang.cindex.Config.set_library_file('C:/Python27/DLLs/libclang.dll') print("Clang path set") index = clang.cindex.Index.create() ... 

I have stripped off all the rest of the code, but I can post them if they are relevant. Line

 index = clang.cindex.Index.create() 

It produces the following error:

 Setting clang path Clang path set Traceback (most recent call last): File "D:\libclangtest\boost_python_gen.py", line 60, in <module> index = clang.cindex.Index.create() File "D:\libclangtest\clang\cindex.py", line 2095, in create return Index(conf.lib.clang_createIndex(excludeDecls, 0)) File "D:\libclangtest\clang\cindex.py", line 141, in __get__ value = self.wrapped(instance) File "D:\libclangtest\clang\cindex.py", line 3392, in lib lib = self.get_cindex_library() File "D:\libclangtest\clang\cindex.py", line 3423, in get_cindex_library raise LibclangError(msg) clang.cindex.LibclangError: [Error 193] %1 is not a valid Win32 application. To provide a path to libclang use Config.set_library_path() or Config.set_library_file(). 

What is the reason for this? Am I setting the dll path incorrectly? I tried several ways, with forces and backslashes, I also tried to move the dll from the Program Files so that the path did not contain spaces, but nothing worked.

I start with libclang and Python if I ask something trivial.

+2
python clang libclang
source share
1 answer

@ SK-logic commented that I should check if both Python and libclang are 32-bit or 64-bit . Libclang was 32 bit, but I could not find a way to check if my Python 32 or 64 installation was installed, so I reinstalled the 32-bit version and now it works. So the problem probably was that I had a 64-bit version of Python.

+3
source share

All Articles