39

I am running an Ubuntu virtual machine with, Python 3.6.1, Anaconda 4.4.0 (64-bit). I am trying to run the code on this website. When I try to use

import cv2.aruco

I get:

>>> import cv2.aruco
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2.aruco'

Is this something I need to install or setup?

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
Maxwell Mullin
  • 509
  • 1
  • 4
  • 10

7 Answers7

54

If cv2.aruco is not found, try installing opencv-contrib-python, such as by running the following (for the default Python installation):

pip install opencv-contrib-python

Or for a specific Python installation (in this case Python 3)

python3 -m pip install opencv-contrib-python

Then try re-running the script trying to access cv2.aruco.

intcreator
  • 4,206
  • 4
  • 21
  • 39
  • 8
    FYI for other readers, the aruco module is not in opencv but in opencv_contrib module, which is why you need to install this package. – saurabheights Jul 01 '18 at 15:01
32

If cv2.aruco is not found, first make sure that opencv-python is not installed.

for that you can use:

pip uninstall opencv-python

Then install:

pip install opencv-contrib-python

We are uninstalling opencv-python because installing two packages of opencv will contradict each other and will not let the other one install.

SaKu.
  • 389
  • 4
  • 8
26

In my case both opencv-python and opencv-contrib-python were installed when I was getting the above error.

So I uninstalled opencv-python using

pip uninstall opencv-python

Run the program and same error. Then I uninstalled opencv-contrib-python

pip uninstall opencv-contrib-python

After that I reinstalled opencv-contrib-python using

pip install opencv-contrib-python

And run the program, no error now. So I upvoted both the above answers :)

Dr. Mian
  • 3,334
  • 10
  • 45
  • 69
4

In case you still need opencv-python for other applications, do the following (in this order, using pip or pip3):

pip3 uninstall opencv-python
pip3 uninstall opencv-contrib-python
pip3 install opencv-python
pip3 install opencv-contrib-python

If you reverse the last two operations, you will still have the error message.

Rexcirus
  • 2,459
  • 3
  • 22
  • 42
4

This version will fix the issue

pip uninstall python-opencv opencv-contrib-python opencv-python 
pip install --upgrade opencv-contrib-python==3.4.2.17

Other answers do not mention versions, that's why they won't be able to fix this issue. cv2.aruco is no longer present in newer versions

Priyanshu
  • 73
  • 6
2

I had both opencv-python and opencv-contrib-python installed in my case when I came across this problem. I've tried pip uninstall opencv-python but the error still appeared. The following command fixed my issue.

pip install opencv-contrib-python-headless

There's probably some version conflix so maybe you should try to uninstall and reinstall certain packages to see which one works. I reinstalled opencv-python after installing opencv-contrib-python-headless and the error did not appear.

abysee
  • 21
  • 3
1

BEWARE: opencv-python version >4.7.0 have now integrated the cv2.aruco module from opencv-contrib-python, as marked here. Therefore, you're not required to handle these two conflicting dependencies. YAY!

There were some code-breaking changes in the aruco module API between 4.6 and 4.7 OpenCV, but these can be easily resolved. This SO helps point out the differences, it's quite minimal.

Eduardo Davalos
  • 161
  • 2
  • 8