Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 877
Hiroyuki Nuri Avatar asked Jun 29 '16 20:06

Hiroyuki Nuri


People also ask

How to import OpenCV to Jupyter Notebook?

You will now be able to import OpenCV to your jupyter notebook. One of possibility is that you could have written import cv2 and its utilisation in separate cells of jupyter notebook.If this is the case then first run the cell having import cv2 part and then run the cell utilising the cv2 library.

Why import on Jupyter Notebook failed where command prompt works?

Problem : Import on Jupyter notebook failed where command prompt works. Reason : This problem usually occurs when your cmd prompt is using different python and Anaconda/jupyter is using different. Run this code in cmd prompt and jupyter notebook and note the output paths.

Is there a module named 'CV2' in Jupiter notebook modulenotfounderror?

No module named 'cv2' in jupiter notebook modulenotfounderror: The specified module cannot be found.

How to check Python version in Jupyter Notebook?

Check python version on your terminal/cmd/powershell. Check version on your Jupyter notebook. They both need to be the same. In order to check whether you are having module installed. Type help ('modules'), and find the module you are trying to work with.


1 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.

like image 154
plfrick Avatar answered Oct 15 '22 10:10

plfrick