简体   繁体   中英

spyder can't import opencv

Basic problem: Spyder-Py2 2.3.3 running can't import cv (commonly known as opencv). When I attempt to "import cv" (or cv2) in a python console, the console doesn't throw an error but just becomes unresponsive. When I attempt to "import cv" in the ipython console, I get "It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console." repeatedly.

Please note this is after I have added /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages to PYTHONPATH using PYTHONPATH manager. If I don't do that, the error simply says the module isn't recognized.

However, in the terminal (OSX 10.9.4) I am able to import cv and use it just fine. Spyder was installed as a .dmg and opencv was installed using Homebrew. Each has been installed and reinstalled a number of times so the order of installation is probably not the problem.

I am pretty sure that terminal and Spyder are using different python sources. In the terminal, "which python" returns /usr/local/bin/python. However, by inspecting sys.version and sys.maxint, you can see both are Python 2.7.8 and 64bit.

The only difference I can find is that in the terminal I get: [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin

Whereas in spyder I get

'2.7.8 (default, Aug 15 2014, 13:43:01) \\n[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.61)]'

when i use sys.version.

This question looks most similar, but the error message is totally different, so I think it is of a different nature.

Please. Any help would be very much appreciated. Chris


Following Carlos' suggestion, I changed the default Python interpreter to /usr/local/bin/python. However, I get a new error message upon starting up Spyder. (Sorry I can't post Images for Rep reasons)

An error ocurred while starting the kernel

Either:

  1. Your IPython frontend and kernel versions are incompatible or
  2. You don't have IPython installed in your external interpreter.

In any case, we're sorry but we can't create a console for you.

I couldn't resolve this by picking a different Python interpreter or by "pip install ipython"

Again install Anaconda and try the following code in Anaconda Prompt to install opencv

conda install --channel https://conda.anaconda.org/menpo opencv3

Then it will work in spyder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM