0

I am trying to import opencv for webcam capturing and Keras to use AI, however, it returns an error showing that the module isn't found.

I used both pip install opencv-python and python -m pip install opencv-python but I still cannot import it.

(I'm using python 3.9.6)

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

You might have python 2.x installed on your machine and is set as default for your pip. You could check this by running pip --version on your terminal and it should show you which version of python it is using. If it shows python 2.x, then you could use pip3 or python3 instead to install your package as you mentioned that you are using python 3.9.6 for your project environment.

For future use, you could set python 3 as your default for pip. You could follow the steps given here: How to override the pip command to Python3.x instead of Python2.7?

Cheers!

Owenn
  • 638
  • 1
  • 6
  • 23
  • did you mean python 3.x? – Albert_coding Aug 16 '21 at 11:41
  • No, you might have python 2.x installed on your machine, that is why when youre using the pip method, you are calling python 2.x instead of python 3.x. Hence, why you should use pip3 install instead because you also mentioned that you are using python 3.9.6 for your project – Owenn Aug 16 '21 at 11:42
  • trying checking the module list though using pip freeze or pip3 freeze – Owenn Aug 16 '21 at 11:43
  • I tried the ```python3 -m pip install opencv-python``` it works now – Albert_coding Aug 16 '21 at 11:45
  • Great, do set this as the accepted answer if you are satisfied with my answer. Thanks Albert happy coding! – Owenn Aug 16 '21 at 11:54