python - MacPorts 安装后,Python 中的 OpenCV 模块失败(退出代码 139)

标签 python macos opencv module

我使用 macports 安装了 opencv,但是当我尝试使用它时 Python 崩溃了:

进程已完成,退出代码为 139

我的 PyCharm IDE 指示 cv2 是一个失败的模块。

失败的模块 Python 2.7.1(/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python) CV2 当模块更新或有新版本的生成器可用时,将再次尝试生成上述模块的骨架

我的 MacPorts 安装 opencv 与 python 2.7 绑定(bind)进行得很顺利,所以我不确定是什么导致了这个错误。我假设 Python 能够导入该库,但不知何故该库或其依赖项失败了。

安装时,我确保首先安装了 numpy(请参阅: How to install Python 2.7 bindings for OpenCV using MacPorts ):

sudo port install opencv +python27

我还在/usr/local 中为 dylibs 创建了软链接(soft link),因为 MacPorts 将它们安装在/opt/local 中。 (参见:How to install Python 2.7 bindings for OpenCV using MacPorts)

最佳答案

我能够通过在本地构建源代码而不是使用 MacPorts 来解决问题。

http://sourceforge.net/projects/opencvlibrary/ 下载 OpenCV 源代码

然后按照 CMake 构建的说明进行操作:http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

如果您没有安装 CMake,请使用 MacPorts 安装它:sudo port install cmake

您需要安装 C++ 编译器,例如 MacOSX 上的 Xcode 3.2 或更高版本

在 OpenCV 文件夹中,

cmake -G "Unix Makefiles"

那么,

make -j8

sudo make install

请务必将/usr/local/lib/python2.7/site-packages 添加到您的 PYTHONPATH 中。

现在运行以下程序:

def main():

 try:
     import cv2
 except ImportError:
     print "cv2 is not installed"
     exit();
 print "looks like its installed "

关于python - MacPorts 安装后,Python 中的 OpenCV 模块失败(退出代码 139),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12702879/

相关文章:

python - 具有分类和连续属性的多类多输出分类,无需在 python 中进行编码

ruby - 在 Mac 上生成音调/正弦波的简单方法? ( ruby 会很好)

android - 使用android openCV进行实时视频处理

python - 使用 Python 验证 SSL 证书

python - 想要每个月的最后一天作为 pandas 中的数据框

c++ - 更改 Mac OS X 上的默认 g++ 架构?

opencv - 在深度图上找到曲率

OpenCV 使用 Hue channel 对货币进行分类

python - pandas.read_csv() 方法中的 `sep` 和 `delimiter` 属性有什么区别?

xcode - 按下按钮时如何显示另一个(更改)ViewController