Python opencv Aruco "No module named 'cv2.aruco'"
Asked Answered
P

7

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?

Predisposition answered 31/8, 2017 at 2:35 Comment(5)
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.Supposing
@ROAR, wow that was an easy fix, thank you!Predisposition
If someone comes looking for the solution: https://pypi.python.org/pypi/opencv-contrib-pythonPredisposition
@MaxMullin I'm going to write this as an official answerCatechin
@ArashRohani It was not in opencv-contirb-python as wellToxic
C
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.

Catechin answered 29/9, 2017 at 16:33 Comment(1)
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.Mange
I
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.

Indonesia answered 23/11, 2018 at 4:30 Comment(0)
H
27

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

Highgrade answered 3/7, 2019 at 10:14 Comment(0)
U
5

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.

Unknot answered 5/2, 2021 at 10:46 Comment(0)
D
5

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

Dresden answered 18/4, 2022 at 8:35 Comment(0)
W
3

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.

Whisenhunt answered 19/12, 2022 at 2:53 Comment(0)
S
2

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.

Shutt answered 9/2, 2023 at 4:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.