0

As far as I can tell I've successfully installed opencv (in two different ways) yet continue to get the error message

ModuleNotFoundError: No module named 'cv2'

First I tried using cmd (ran as administrator)

pip install cv2

I don't recall why that didn't work but found this.

I'm running Windows 7 32-bit and have Python 3.7 installed. So I chose:

opencv_python‑4.1.0‑cp37‑cp37m‑win32.whl

from here but got the message:

Error opencv_python.....whl is not a supported wheel on this platform.

Then based on this I tried this:

pip install opencv-contrib-python 

That successfully installed.

But when I ran the following (in Jupyter):

import cv2

I get the error

ModuleNotFoundError: No module named 'cv2'.

Having no idea why I got the error, in desperation I tried installing other wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/, chosing older versions from the initial one I failed to install.

I finally succeeded in installing this one:

opencv_python-4.1.0-cp36-cp36m-win32.whl

So I went back to Jupyter and re-attempted to import cv2 but got the same error message.

I tried restarting the Jupyter kernel and even restarting my laptop to no avail.

I've scanned through other SO threads with the same error listed and tried what was suggested - e.g. one thread (can't find it to copy the link here) had the suggestion to try:

conda create --name opencv-env python=3.7

but I got:

Fetching package metadata ............. PackageNotFoundError: Package not found: Conda could not find '

I'm out of ideas. Any suggestions out there?

nathancy
  • 42,661
  • 14
  • 115
  • 137
critor
  • 173
  • 2
  • 11
  • Try ensure your openCV version is up to date with `pip install --upgrade opencv-python` and `pip install --upgrade opencv-contrib-python` – nathancy Jun 14 '19 at 20:31
  • Thanks for the suggestions. The first command skipped some ("requirement already satisfied"), downloaded a package, installed opencv-python, found an existing 4.1.0 installation, uninstalled it, then re-installed 4.1.0.25. The second command reported "Requirements already up-to-date" or "..already satisfied". I re-ran "install cv2" after running each, and in both cases, received the same error. – critor Jun 14 '19 at 20:57
  • You probably have multiple Python versions installed. Make sure you install and use opencv from the same Python installation. – cgohlke Jun 14 '19 at 23:03
  • delete all opencv first by pip uninstall. then install a clean one that you wish to use. Set up the source correctly in the bashrc folllowing this link https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/. Or the simplist way is to use conda to help you get the correct environment following this linke https://stackoverflow.com/questions/23119413/how-do-i-install-python-opencv-through-conda – Dr Yuan Shenghai Jun 15 '19 at 01:36
  • Thanks for the additional help. I suspect that (one of possibly many) issues is having (as @cgohlke rightly pointed out) multiple versions of Python, as well as multiple versions of Anaconda (that possibly don't all match the Python versions I have installed). Also I read somewhere else something about [path environment variables](https://stackoverflow.com/questions/2547554/multiple-python-versions-on-the-same-machine), which I don't understand but suspect this is crucial. – critor Jun 16 '19 at 08:54
  • Thanks also @Dr Yuan Shenghai. I'm currently uninstalling Python2 and all versions of Anaconda that pre-date Python3.7. Then I'll have a go at those links. :) – critor Jun 16 '19 at 08:54

0 Answers0