Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2445

No module named 'cv2.cv2'

I am a beginner at computers. I use Anaconda python 3.6 in windows 10. I have already installed OpenCV using this command:

pip install opencv-python

But when I try to import cv2 using this:

import cv2

this error shows up:

cv2 error

How can I install openCV for python?

Upvotes: 12

Views: 66160

Answers (8)

cherry
cherry

Reputation: 356

I was facing a similar issue. In my case, the issue occured because of previous dependencies.

!pip install easyocr
!pip install imutils

if you are running these commands first and then importing

import cv2
from matplotlib import pyplot as plt
import numpy as np
import imutils
import easyocr

then you will get this error. So you first import CV2 and then pip install easyocr or other libraries. This worked in my case.

Upvotes: 1

ondas
ondas

Reputation: 119

This happened to me because I setup a virtual environment with python 32-bit and my modules required the 64-bit version so it seemed there was a version conflict of CV. Changing the python version in my environment fixed the issue.

Upvotes: 2

Dogamo
Dogamo

Reputation: 9

Try reinstalling openCV — it worked for me.

To uninstall:

pip uninstall opencv-python

To reinstall:

pip install opencv-python

Upvotes: 0

Martín Gonzalez
Martín Gonzalez

Reputation: 31

In my case, using Python 3.8 on Windows 10 and Pycharm (or VS Code as well), I have this same issue.

Finally I noticed that the Antivirus (Nod32) deletes the cv2.cp38-win32.pyd file that should be in the cv2 folder. I simply paused the protection, installed opencv with pip install opencv-python command and it worked just fine.

I hope it helps someone.

Upvotes: 3

seas and mountains
seas and mountains

Reputation: 345

I had this exact same problem on Windows 10. Uninstalling via pip and then reinstalling in my virtual environment fixed everything up for me.

Here's a link that helped https://pypi.org/project/opencv-python/

Upvotes: 0

Mohamed Imran
Mohamed Imran

Reputation: 219

Based on python opencv link: https://pypi.org/project/opencv-python/

Step 1: Uninstall the opencv first if you have previous/other manually installed (= not installed via pip) version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages)):

pip uninstall opencv-python

Step 2: Install the package afresh

pip install opencv-python

Hope that works!

Upvotes: 21

Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2445

I used the answer provided here and it worked.

By running pip install opencv_python-3.4.5-cp36-cp36m-win_amd64.whl

Upvotes: 0

blacker
blacker

Reputation: 798

try this:

Create Virtual Environment

conda create --name opencv-env python=3.6

Activate the environment

activate opencv-env

Install OpenCV and other important packages

pip install numpy scipy matplotlib scikit-learn jupyter
pip install opencv-contrib-python
pip install dlib

Test your installation

import cv2
cv2.__version__

Upvotes: 7

Related Questions