36

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?

5
  • 1
    I haven't used aruco but with a quick search it seems like it's in the opencv_contrib and not the main opencv. So it depends if you included opencv_contrib in your build. Aug 31, 2017 at 3:03
  • @ROAR, wow that was an easy fix, thank you! Aug 31, 2017 at 12:39
  • 1
    If someone comes looking for the solution: https://pypi.python.org/pypi/opencv-contrib-python Aug 31, 2017 at 12:40
  • 1
    @MaxMullin I'm going to write this as an official answer
    – intcreator
    Sep 29, 2017 at 16:30
  • @ArashRohani It was not in opencv-contirb-python as well
    – Behroz
    Aug 6, 2022 at 18:21

7 Answers 7

48

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.

1
  • 7
    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. Jul 1, 2018 at 15:01
31

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.

25

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 :)

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.

3

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

1

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.