Folgende Eli's und glehmann's Führungen;Kann libclang nicht ausführen: Fehler '' spezifiziertes Modul konnte nicht gefunden werden ''
(unter 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
Wenn ich versuche, unter dem Code auszuführen (aus den Führungen genommen, die ich oben erwähnt)
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')
ich die folgenden Fehlermeldung erhalten:
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
Auch versucht,
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')
ohne Erfolg.
Haben Sie versucht, set_library_file anstatt set_library_path? –
Ja, ich tat genau denselben Fehler. :( –
Es sieht aus wie Sie ein paar mögliche Probleme haben. 1) Sie sind nicht sicher, warum die DLL gefunden wird; 2) Sie sind nicht sicher, ob Sie eine kompatible Reihe von Python-Bindungen haben. Die Python-Bindings (alle von ihnen) enthalten genug Funktionalität, um das zu tun, was Sie erhoffen (also ist es kein Problem) - ich bin zuversichtlich, weil die Implementierung auf Ctypes basiert. Wenn das die DLL-Problem kann Sie die cindex.py-Datei manuell bearbeiten, um genau zu drucken, welche Datei geöffnet wird, wenn Sie auch os.path.exists behaupten, erhalten Sie möglicherweise ein wenig mehr Einblick in was schief geht –