jj pan
jj pan

Reputation: 307

ImportError: No module named 'cv2' using jupyter

I am trying to import OpenCV into my ipynb using Jupyter. I kept getting :

ImportError: No module named 'cv2'

import cv2
import pandas as pd
import numpy as np
import matplotlib

from matplotlib import pyplot as plt
import seaborn as sns

Any idea how to import cv2 in jupyter?

Upvotes: 10

Views: 20979

Answers (4)

Awais Khan
Awais Khan

Reputation: 37

If you are a tensorflow user on jupyter notebook. So, I can explained you how I get rid of this problem.

On Command Line..

  1. Conda activate tensorflow when you got this interface. (tensorflow) xx.

Now, type: 2. pip install opencv-python.

This would definitely solve the problem.

Upvotes: 0

Sam
Sam

Reputation: 1

OpenCV is compiled for Python 2.7. When you install it with pip, it will install 2.7. However, if you run the code with python 3, it will complain that the module is not installed. using the command sudo apt-get install python3-opencv

Solved my problem, hope it will help others

Upvotes: 0

neurobot
neurobot

Reputation: 426

You can type

which jupyter-notebook

if it's not in the envs of opencv-python installed, you should install jupyter in the envs:

condda install jupyter-notebook

Upvotes: 1

alif
alif

Reputation: 805

If you have already installed opencv, then its possible that your notebook and your opencv library are in 2 different python environments. The following has helped me in the past:

  1. Open your notebook
  2. In an new cell type:

!pip install opencv-python

Note, that the ! is deliberate. This will install open-cv in your current notebook environment.

Upvotes: 18

Related Questions