正在關注Eli's和glehmann's指南;無法運行libclang:錯誤''指定的模塊找不到''
(在Windows)
installed LLVM-3.8.0-win32 from here
installed libclang-py3 package (version 0.3)
added
C:\Program Files (x86)\LLVM\bin\libclang.dll
to my Path environment variables
當我嘗試執行下面的代碼(從導遊採取我上面提到)
clang.cindex.Config.set_library_path('C:\Program Files (x86)\LLVM\bin\libclang.dll')
def find_typerefs(node, typename):
# Find all references to the type named 'typename'
if node.kind.is_reference():
ref_node = clang.cindex.Cursor_ref(node)
if ref_node.spelling == typename:
print('Found %s [line=%s, col=%s]' % (
typename, node.location.line, node.location.column))
# Recurse for children of this node
for c in node.get_children():
find_typerefs(c, typename)
index = clang.cindex.Index.create()
tu = index.parse(cppsource)
print('Translation unit:', tu.spelling)
find_typerefs(tu.cursor, 'Person')
我收到以下錯誤:
C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Duca/Desktop/PyPlag/rough-scripts/c++_parser_with_libclang.py
Traceback (most recent call last):
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3623, in get_cindex_library
library = cdll.LoadLibrary(self.get_filename())
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\ctypes\__init__.py", line 425, in LoadLibrary
return self._dlltype(name)
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Duca/Desktop/PyPlag/rough-scripts/c++_parser_with_libclang.py", line 49, in <module>
index = clang.cindex.Index.create()
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 2238, in create
return Index(conf.lib.clang_createIndex(excludeDecls, 0))
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 141, in __get__
value = self.wrapped(instance)
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3592, in lib
lib = self.get_cindex_library()
File "C:\Users\Duca\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clang\cindex.py", line 3628, in get_cindex_library
raise LibclangError(msg)
clang.cindex.LibclangError: [WinError 126] The specified module could not be found. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
Process finished with exit code 1
也試過,
downloaded cfe-3.8.0.src.tar from here and copied the
clang.cindex
module inside my script's directoryinstalled LLVM-3.8.0-win64 and updated the Path environment variable as well as the
clang.cindex.Config.set_library_path
statement (after reading this question)copied the
libclang.dll
from the installation dir to my Python DLLs dirused
clang.cindex.Config.set_library_path('C:\Program Files (x86)\LLVM\bin')
andclang.cindex.Config.set_library_file('C:\Program Files (x86)\LLVM\bin\libclang.dll')
andclang.cindex.Config.set_library_file('C:\Program Files (x86)\LLVM\bin')
沒有成功。
你試過set_library_file而不是set_library_path了嗎? –
是的,完全一樣的錯誤。 :( –
它看起來像你有幾個可能的問題。1)你不知道爲什麼DLL被發現; 2)你不確定你是否有一組兼容的Python綁定。 python綁定(其中任何一個)都將包含足夠的功能來執行你所希望的功能(所以這不是問題) - 我對此很有信心,因爲實現基於ctypes。如果這留下的DLL問題,你可以手動編輯cindex.py文件打印準確打印哪個文件,如果你還'斷言os.path.exists'你可能會更深入瞭解什麼是錯誤 –