为什么不能这个python脚本找到libclang dll? [英] Why can't this python script find the libclang dll?

查看:1876
本文介绍了为什么不能这个python脚本找到libclang dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始使用 libclang Python 。我想要获取示例代码( http ://www.altdevblogaday.com/2014/03/03/implementing-a-code-generator-with-libclang/ )在 Windows 上工作,这里是代码我试图运行:

 #!/ usr / bin / python 
#vim:set fileencoding = utf-8

import sys
import os
import clang.cindex
import itertools

...

print(设置铛路径)
#我尝试了多个变体。 Libclang已正确安装在指定位置。
#clang.cindex.Config.set_library_path('C:/ Program Files(x86)/ LLVM / bin')
#clang.cindex.Config.set_library_path /LLVM/bin/libclang.dll')

#我也尝试将dll移动到Python安装文件夹。
clang.cindex.Config.set_library_file('C:/Python27/DLLs/libclang.dll')
print(Clang path set)

index = clang.cindex .Index.create()

...

代码的其他部分,但我可以发布他们,如果他们相关。

  index = clang.cindex.Index.create()
pre>

抛出以下错误:

 设置铛路径
Clang path set
Traceback(最近一次调用):
文件D:\libclangtest\boost_python_gen.py,第60行,在< module>
index = clang.cindex.Index.create()
文件D:\libclangtest\clang\cindex.py,第2095行,在create
中return index lib.clang_createIndex(excludeDecls,0))
文件D:\libclangtest\clang\cindex.py,第141行,在__get__
value = self.wrapped(instance)
在lib
中的文件D:\ libclangtest\clang\cindex.py,第3392行lib = self.get_cindex_library()
文件D:\libclangtest\clang\ cindex.py,行3423,在get_cindex_library
raise LibclangError(msg)
clang.cindex.LibclangError:[错误193]%1不是有效的Win32应用程序。要提供libclang的路径,请使用Config.set_library_path()或Config.set_library_file()。

这是什么原因?我设置dll的路径错了吗?我尝试了多种方式,使用foreslashes和反斜杠,我也试图移动dll从程序文件,使路径不包含空格,但没有什么工作。



解决方案

@ SK-逻辑

/ strong>评论说,我应该检查Python和libclang是否 32位或64位。 libclang是32位,但我找不到一个方法来检查我的Python安装是32还是64,所以我重新安装32位版本,现在它的工作原理。所以问题可能是我有64位版本的Python。


I would like to get started with 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/) to work on Windows, here is a 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 stripped all the other parts of the code, but I can post them if they are relevant. The line

index = clang.cindex.Index.create()

Throws 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's path wrong? I tried multiple ways, with foreslashes and backslashes, I also tried to move the dll out of Program Files to make the path contain no spaces, but nothing worked.

I am a total beginner to libclang and Python, sry if I'm asking something trivial.

解决方案

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

这篇关于为什么不能这个python脚本找到libclang dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆