Python ctypes无法在Mac OS X上加载动态库 [英] Python ctypes not loading dynamic library on Mac OS X

查看:679
本文介绍了Python ctypes无法在Mac OS X上加载动态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++库repeater.so,可以通过以下方式从Linux中的Python加载该库:

I have a C++ library repeater.so that I can load from Python in Linux the following way:

import numpy as np                                    
repeater = np.ctypeslib.load_library('librepeater.so', '.')

但是,当我在Mac OS X(Snow Leopard,32位)上编译相同的库并获得repeater.dylib,然后在Python中运行以下代码时:

However, when I compile the same library on Mac OS X (Snow Leopard, 32 bit) and get repeater.dylib, and then run the following in Python:

import numpy as np                                
repeater = np.ctypeslib.load_library('librepeater.dylib', '.')

我收到以下错误:

OSError: dlopen(/mydir/librepeater.dylib, 6): no suitable image found.  Did find:
    /mydir/librepeater.dylib: mach-o, but wrong architecture

在Mac OS X上的Python中加载动态库时,我需要做些不同的事情吗?

Do I have to do something different to load a dynamic library in Python on Mac OS X?

推荐答案

不是.如错误消息所述,您的python和librepeater.dylib文件之间存在体系结构不匹配.使用file来检查librepeater.dylib的体系结构;您的python将使用未列出的Python之一构建.

Nope. As the error message says, there's an architecture mismatch between your python and librepeater.dylib file. Use file to check what the architecture of librepeater.dylib is; your python is going to be built using one of the ones not listed.

这篇关于Python ctypes无法在Mac OS X上加载动态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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