问题
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