【发布时间】:2019-11-23 23:52:44
【问题描述】:
我尝试在命令行上运行 python 代码。我遇到错误OSError: [WinError 193] %1 is not a valid Win32 application。
我是 python clang 包装函数的新手。 我正在使用 32 位的 python 3.7.2。 我正在使用 64 位版本 7.1.0 的 llvm。
#!/usr/bin/env python
import sys
import clang.cindex
import ctypes
clang.cindex.Config.set_library_path('C:/Program Files/LLVM/bin')
print("argument1 ------> ",sys.argv[1])
print("argument2 ------> ",sys.argv[2])
def find_typerefs(node, typename):
if node.kind.is_reference():
ref_node = node.get_definition()
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(sys.argv[1])
print( 'Translation unit:', tu.spelling)
find_typerefs(tu.cursor, sys.argv[2])
我尝试使用 subprocess.call([sys.executable, 'parser.py', 'dummyC++.cpp','person'],shell=True) 并得到同样的错误
File "C:\Python37-32\lib\site-packages\clang\cindex.py", line 4129, in get_cindex_library
library = cdll.LoadLibrary(self.get_filename())
File "C:\Python37-32\lib\ctypes\__init__.py", line 434, in LoadLibrary
return self._dlltype(name)
File "C:\Python37-32\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "parser.py", line 30, in <module>
index = clang.cindex.Index.create()
File "C:\Python37-32\lib\site-packages\clang\cindex.py", line 2666, in create
return Index(conf.lib.clang_createIndex(excludeDecls, 0))
File "C:\Python37-32\lib\site-packages\clang\cindex.py", line 198, in __get__
value = self.wrapped(instance)
File "C:\Python37-32\lib\site-packages\clang\cindex.py", line 4103, in lib
lib = self.get_cindex_library()
File "C:\Python37-32\lib\site-packages\clang\cindex.py", line 4134, in get_cindex_library
raise LibclangError(msg)
clang.cindex.LibclangError: [WinError 193] %1 is not a valid Win32 application. To provide a path to libclang use Config.set_library_path() or Config.set_library_file().
这是错误信息
【问题讨论】:
-
@frankegoesdown 尝试了该解决方案。但仍然面临同样的错误。
标签: python