为什么不能在IPython笔记本中导入OpenCV(cv2)? [英] Why can't I import OpenCV (cv2) in IPython notebook?

查看:63
本文介绍了为什么不能在IPython笔记本中导入OpenCV(cv2)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我跑步

导入cv2

在IPython笔记本单元中,出现错误屏幕,并显示以下消息

in an IPython notebook cell, I get an error screen with the message

 Kernel Restarting
 The kernel appears to have died. It will restart automatically.

然后另一个对话框指出python意外退出.这是否意味着我无法在IPython中运行OpenCV?我似乎无法通过谷歌搜索找到解决方案.

Then another dialog stating python quit unexpectedly. Does this mean I cannot run OpenCV in IPython? I cannot seem to find the solution to this anywhere by googling.

这个问题有解决方案吗?

Is there a solution to this problem?

平台:Mac OSX:10.9,IPython 4.0.3,Python 2.7.9

Platform: Mac OSX:10.9, IPython 4.0.3, Python 2.7.9

推荐答案

我的终端和许多其他使用OpenCV的cv2的应用程序实际使用的python shell是通过

The actual python shell that was used by my terminal and many other applications that used OpenCV's cv2 properly was obtained by

which python

在终端中.它返回了/opt/local/bin/python

IPython的可执行文件位于/usr/local/bin/ipython 中-打开它(可能需要超级用户特权)

The executable for IPython was located in /usr/local/bin/ipython -- Open it (it may require superuser privileges)

sudo nano /usr/local/bin/ipython

您会发现文件的第一行是#!/usr/bin/python ,这将导致 ipython 执行默认的编译器.必须将其替换为#!/opt/local/bin/python 行.

You'd find that the first line of the file is #!/usr/bin/python which causes ipython to execute the default compiler. This had to be replaced with the line #!/opt/local/bin/python.

然后问题已解决.我像往常一样启动了IPython笔记本,并执行了 import cv2 ,它运行顺利,没有任何故障!

Then the problem was fixed. I started the IPython notebook as usual and executed import cv2 and it went well without a glitch!

这篇关于为什么不能在IPython笔记本中导入OpenCV(cv2)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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