我使用 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/