Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the loading error of clang's Python binding?

I'm trying the Python binding for clang. I installed LLVM and its python bindings using homebrew on Mac OS X Maverics with command line

 brew install llvm --with-clang --with-python --with-lld

The loading code is

import clang
import clang.cindex

clang.cindex.Config.set_library_path('/usr/local/Cellar/llvm/3.5.0/lib')
index = clang.cindex.Index.create()

But this throws an error:

clang.cindex.LibclangError: dlopen(/usr/local/Cellar/llvm/3.5.0/lib/libclang.dylib, 6): Library not loaded: @rpath/libLLVM-3.5.dylib Referenced from: /usr/local/Cellar/llvm/3.5.0/lib/libclang.dylib Reason: image not found. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().

But I don't understand why this error occurs. Doesn't @rpath here refers to /usr/local/Cellar/llvm/3.5.0/lib? But there is a file called libLLVM-3.5.dylib under that directory. Why does this loading cause an error and how to fix it?

like image 276
Siyuan Ren Avatar asked Sep 23 '14 17:09

Siyuan Ren


1 Answers

Elevating @synthesizerpatel's comment to an answer:

Add the following environment variable to your environment:

 DYLD_LIBRARY_PATH=/usr/local/Cellar/llvm/3.5.0/lib/

The readme also mentions

You may need to alter LD_LIBRARY_PATH so that the Clang library can be found.

like image 117
jxramos Avatar answered Nov 01 '22 22:11

jxramos