0

No matter what I install, it's either opencv-python, opencv-contrib-python or both at the same time, I keep getting the "No module named 'cv2'" error. I couldn't find an answer here. Some say that only opencv-python works, others say opencv-contrib-python works. I tried everything but nothing seems to work. I'm trying to use the aruco function and I know it belongs to the contrib module. Any tip? Thanks

GZanotto
  • 31
  • 3

2 Answers2

0

Did you try to restart your code editor? I often need to close the file or whole VScoode and reopen for it to see the library I just installed.

Another problem could be that you're installing cv2 to a python verse that youre not using on your code editor.. If youre using python2.9 on your code editor but you install cv2 on your terminal with "pip3.10 install opencv-python" command, your code editor wont find it

Sol_is_here
  • 110
  • 9
  • Yes, I tried closing VSCode and reopening but it's still the same. Where can I check the version of my code editor? I installed Python 3.10 for the first time some days ago so i dont think i can have two versions of python – GZanotto Aug 18 '22 at 22:22
  • There must be a default python version installed on your computer. To check which python version your code editor using, create a python file (example.py) and run "import sys print (sys.version)" – Sol_is_here Aug 18 '22 at 22:35
  • If it prints some other python version than 3.10, then you need to search about how to update python verse on VScode on your system (windows, mac, linux, whichever youre using). If it prints 3.10, then good news, there is no problem with your python verse. The bad news is, your "no module found" error still isnt solved... – Sol_is_here Aug 18 '22 at 22:41
  • Welp I have 3.10.6 both in VSCode and in my terminal. Any other idea? – GZanotto Aug 18 '22 at 22:46
  • Not really... It really looks like your code editor cant reach to the python verse you installed opencv with, either because of youre using virtual environment or cuz of a new python installment. Can you try on your VScode terminal "pip show opencv-python". If you installed everything right, it should show you the version of your opencv and other details about the library – Sol_is_here Aug 18 '22 at 23:00
  • Another idea would be installing another library just to double check that its about opencv and not about your system&code editor&python verse... – Sol_is_here Aug 18 '22 at 23:02
  • I have installed another libraries and everything seems to be alright :/ This is really messy – GZanotto Aug 18 '22 at 23:41
  • It is!... You know what? Sometimes libraries dont work with the latest python version. I for myself, know that opencv works with python3.10. But maybe it creates problems with 3.10.6? Anywho, dont forget to update here when you find a solution. I'm curious – Sol_is_here Aug 19 '22 at 00:37
  • You were right, it seems I had another version of python I installed from Microsoft Store I forgot about and when I installed things with pip, it was installing it on one version and VSCode was running the other one. So it's my bad. Thanks for the help! – GZanotto Aug 19 '22 at 14:55
0

I would recommend using conda and creating a new enviroment. Then try sudo pip3 install opencv-python if youre using python3 or you can try sudo pip install opencv-python if you're using python2. This worked for me.

Another tip is to always check that you have the newest version of pip pip install --upgrade pip