Python opencv Aruco "No module named 'cv2.aruco'"

72.2k views Asked by At

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?

7

There are 7 answers

1
intcreator On BEST ANSWER

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.

0
Priyanshu On

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

0
SaKu. On

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.

0
abysee On

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.

0
Rexcirus On

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.

0
Eduardo Davalos On

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.

0
drmaa On

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