我通过extractor
在python 2.7中使用pip install extractor
模块。我在OS X上使用自制程序,我之前运行过homebrew install libextractor
。这将在/ usr / local / lib中创建扩展名为.a和.dylib的文件。 (GNU libextractor)
在extractor.py的第36行附近,有以下代码:
try: #loading shared object file libextractor = cdll.LoadLibrary('libextractor.so.3') except OSError: libextractor = cdll.extractor
从python shell尝试OSError: dlopen(extractor, 6): image not found
时,我得到import extractor
。
这似乎是因为我没有.so.3文件,并且在模块中硬编码。但错误来自于except块,而不是try块。
这个错误是由于libextractor.so.3的硬编码引起的,如果是这样,我怎么能告诉python加载正确的库?我已经尝试用存在的各种文件(.a,.dylib)替换该值,但没有运气。
答案 0 :(得分:2)
如果有效,你应该使用ctype.CDLL(" libextractor")让ctypes找出正确的扩展名。可悲的是,特定于操作系统的扩展魔法不存在。
ctypes
提供find_library
方法,如果有效,请使用它。遗憾的是,它依赖于外部程序,这意味着在小型或奇怪的系统上运行时命中和破坏。
other projects went ahead and hardcoded extension基于os.uname()。如果你不得不这样做。
P.S。 except子句是一些奇怪的解决方法,实际上ctypes.cdll.foo
相当于ctypes.cdll.__getattr__("foo")
,它与ctypes.CDLL("foo")
相同,没有lib-
或扩展名就无法工作。
答案 1 :(得分:0)