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

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

问题描述

每当我跑步时

import 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

推荐答案

解决方案的轻微变体< a href =https://stackoverflow.com/questions/9386048/ipython-reads-wrong-python-version。>这篇文章解决了我的问题。

The slight variant of the solution to this post solved my problem.

我的终端和许多其他正确使用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

你会发现第一行的file是#!/ 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天全站免登陆