Cv2 Import Error on Jupyter Notebook

I'm trying to import cv2 on Jupyter notebook but I get this error:

ImportError: No module named cv2

I am frustrated because I'm working on this simple issue for hours now. it works on Pycharm but not on Jupiter notebook. I've already installed cv2 into Python2.7's site packages, configured Jupyter's kernel to python2, browsed the documentation but I still don't get what I am missing ?

(I'm using windows 10 and working with microsoft cognitives api, that's why I need to import this package.)

here is the code:

 <ipython-input-1-9dee6ed62d2d> in <module>()
----> 1 import cv2
      2 cv2.__version__

What should I do in order to make this work ?

14 Answers

Is your python path looking in the right place? Check where python is looking for the module. Within the notebook try:

import os
os.sys.path

Is the cv2 module located in any of those directories? If not your path is looking in the wrong place. If it is overlooking the install location, append it to your python path. You can follow the instructions here.

2

I didn't have the openCV installation in my Python3 kernel, so I installed it by activating the specific environment and running this in the command prompt:

pip install opencv-python

How to find and activate my environment?

To list all of Your conda environments, run this command:

conda info --envs

You will get something like this:

ipykernel_py2            D:\Anaconda\envs\ipykernel_py2
root                     D:\Anaconda

After that, activate the environment that is complaining for the missing cv2 and run the pip install opencv-python command.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.