Why can't I import OpenCV (cv2) in IPython notebook?

自古美人都是妖i 提交于 2019-12-12 02:39:39

问题


Whenever I run

import cv2

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.

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?

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


回答1:


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

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

in the Terminal. It returned /opt/local/bin/python

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

sudo nano /usr/local/bin/ipython

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.

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



来源:https://stackoverflow.com/questions/34998652/why-cant-i-import-opencv-cv2-in-ipython-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!