-1

I have a problem with installing the opencv package aruco. Im using Windows 10 and pycharm as IDE. I already tried the following things: using 2 different python versions (3.10/3.6)

pip install opencv-python
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-contrib-python

and i tried it with pip3 aswell.

if i want to install aruco with pycharm (hovering over aruco and press install package)

im getting the following Error: enter image description here

and the following Error, if i try to install it with the terminal

pip3 install aruco

Collecting aruco
  Using cached aruco-3.1.12.0.tar.gz (169 kB)
  Preparing metadata (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\lenna\appdata\local\programs\python\python36\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\lenna\\AppData\\Local\\Temp\\
pip-install-c53lxxn7\\aruco_13ecc0ff23e64bae9b37865132c68cea\\setup.py'"'"'; __file__='"'"'C:\\Users\\lenna\\AppData\\Local\\Temp\\pip-install-c53lxxn7\\aruco_13ecc0ff23e64bae9b3786513
2c68cea\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read
().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\lenna\AppData\Local\Temp\pip-pip-egg-info-mbopbdpu'     
       cwd: C:\Users\lenna\AppData\Local\Temp\pip-install-c53lxxn7\aruco_13ecc0ff23e64bae9b37865132c68cea\
  Complete output (9 lines):
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\lenna\AppData\Local\Temp\pip-install-c53lxxn7\aruco_13ecc0ff23e64bae9b37865132c68cea\setup.py", line 6, in <module>
      import numpy as np
    File "c:\users\lenna\appdata\local\programs\python\python36\lib\site-packages\numpy\__init__.py", line 124, in <module>
      from numpy.__config__ import show as show_config
    File "c:\users\lenna\appdata\local\programs\python\python36\lib\site-packages\numpy\__config__.py", line 12, in <module>
      os.add_dll_directory(extra_dll_dir)
  AttributeError: module 'os' has no attribute 'add_dll_directory'
  ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/25/12/38360e882310c4db448e50cd3e98e6cc376e95fa03cb1313d7e301bca8a8/aruco-3.1.12.0.tar.gz#sha256=b62a2f0acebd3e130b114005a258
ae8d6bf89890f779dee965b4778fd6589f48 (from https://pypi.org/simple/aruco/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.    
  Using cached aruco-3.1.2.0.tar.gz (654 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: numpy in c:\users\lenna\appdata\local\programs\python\python36\lib\site-packages (from aruco) (1.23.1)
Requirement already satisfied: opencv-contrib-python in c:\users\lenna\appdata\local\programs\python\python36\lib\site-packages (from aruco) (4.6.0.66)
Using legacy 'setup.py install' for aruco, since package 'wheel' is not installed.
Installing collected packages: aruco
    Running setup.py install for aruco ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\lenna\appdata\local\programs\python\python36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\lenna\\AppData\\Local\\T
emp\\pip-install-c53lxxn7\\aruco_f8d3352f51c94f938d5a719818f5543e\\setup.py'"'"'; __file__='"'"'C:\\Users\\lenna\\AppData\\Local\\Temp\\pip-install-c53lxxn7\\aruco_f8d3352f51c94f938d5a
719818f5543e\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f
.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\lenna\AppData\Local\Temp\pip-record-v_7cn6ey\install-r
ecord.txt' --single-version-externally-managed --compile --install-headers 'c:\users\lenna\appdata\local\programs\python\python36\Include\aruco'
         cwd: C:\Users\lenna\AppData\Local\Temp\pip-install-c53lxxn7\aruco_f8d3352f51c94f938d5a719818f5543e\
    Complete output (11 lines):
    c:\users\lenna\appdata\local\programs\python\python36\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.6
    copying aruco.py -> build\lib.win-amd64-3.6
    running build_ext
    building '_aruco' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\lenna\appdata\local\programs\python\python36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:
\\Users\\lenna\\AppData\\Local\\Temp\\pip-install-c53lxxn7\\aruco_f8d3352f51c94f938d5a719818f5543e\\setup.py'"'"'; __file__='"'"'C:\\Users\\lenna\\AppData\\Local\\Temp\\pip-install-c53
lxxn7\\aruco_f8d3352f51c94f938d5a719818f5543e\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools imp
ort setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\lenna\AppData\Local\T
emp\pip-record-v_7cn6ey\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\lenna\appdata\local\programs\python\python36\Include\aruco' Check 
the logs for full command output.
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

2 Answers2

2

You are trying to use OpenCV's ArUco module. aruco is a module from OpenCV's contrib collection of modules. It is not a separate package. Do not attempt to "pip install aruco". That will give you something else that has nothing to do with OpenCV, and it'll be troublesome as you've noticed.

Make sure to pip install opencv-contrib-python, but not opencv-python. Both packages contain base modules, only the contrib package contains contrib modules. Both packages conflict, so only install one of them.

You do not need to import the submodule specifically. Just...

import cv2 as cv

and then cv.aruco.whatever... classes and functions are available.

the "cp36" wheel will also install on later Python versions (explicitly also 3.9 and 3.10) without needing any compilation at all because it is conforming to abi3, a "stable ABI". More here: https://docs.python.org/3/c-api/stable.html

I repeat: installation does not need compilation at all. It is a binary package. As long as you stick with currently supported versions of Python, and common operating systems on common CPU architectures, you need to do nothing but pip install opencv-contrib-python.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
0

Update: It seems I misunderstood the issue. Your problem isn't installing aruco, though if you want to install that, or a similar C/C++ extension, then your answer is installing a proper compiler.

For cv2.aruco, as mentioned by Christoph Rackwitz is to install the opencv-contrib-python. But watch out for the available versions (win32/win_amd64 and its abi tag (1, 2)) otherwise you'll fallback to the compilation again if there is a mismatch.

Here is an example with Python 3.6, Alpine Linux and the latest contrib version (4.6.0.66):

$ docker run -it python:3.6 bash
Digest: sha256:f8652afaf88c25f0d22354d547d892591067aa4026a7fa9a6819df9f300af6fc
Status: Downloaded newer image for python:3.6
root@49ebb1c3500d:/# pip install opencv-contrib-python
Collecting opencv-contrib-python
  Downloading opencv_contrib_python-4.6.0.66-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (67.1 MB)
     |████████████████████████████████| 67.1 MB 24 kB/s 
Collecting numpy>=1.13.3
  Downloading numpy-1.19.5-cp36-cp36m-manylinux2010_x86_64.whl (14.8 MB)
     |████████████████████████████████| 14.8 MB 10.3 MB/s 
Installing collected packages: numpy, opencv-contrib-python
Successfully installed numpy-1.19.5 opencv-contrib-python-4.6.0.66
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root@49ebb1c3500d:/# python
Python 3.6.15 (default, Dec 21 2021, 12:03:22) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/local/lib/python3.6/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
root@49ebb1c3500d:/# apt update&&apt install libgl1
root@49ebb1c3500d:/# python
Python 3.6.15 (default, Dec 21 2021, 12:03:22) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.aruco
<module 'cv2.aruco'>

Read the error message:

Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

You need to download the (C/C++) compiler from here so that the C/C++ extension code can be compiled. Otherwise the aruco package, which is just a SWIG-generated wrapper for aruco, can't be installed.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • and how can i use the submodule then? – blumentopf111 Jul 24 '22 at 12:42
  • this is a python/OpenCV issue. you're on the entirely wrong path with this answer. the issue is simply that OP hasn't installed the correct package. there is no separate aruco package. it's a submodule of opencv. – Christoph Rackwitz Jul 24 '22 at 12:42
  • @ChristophRackwitz Thanks! Also, there is such a package, see the links in the original answer. OpenCV is just packaging it differently. :) – Peter Badida Jul 24 '22 at 13:01
  • @blumentopf111 See the updated answer. Also unless your Python matches any of the `cpXX` that also has `win32` in its name, you'll need to compile, therefore install a compiler first. – Peter Badida Jul 24 '22 at 13:02
  • 1
    still incorrect. the opencv-python **binary** packages for windows, hosted on PyPI, work perfectly fine for python 3.9 and 3.10. there is **absolutely no need to compile anything** here, if the host system is windows or linux on x64. that's the whole point of binary packages. -- also, opencv's aruco isn't "repackaged". it's its own branch of the aruco code, and arguably not getting maintained that well, but anyway, it's not just a copy of something else. -- the github repo you linked to is some random person's python bindings... which requires OpenCV! just use OpenCV's aruco... – Christoph Rackwitz Jul 24 '22 at 13:44
  • @ChristophRackwitz Where exactly do you see the Python 3.9/3.10 ***binary*** packages in https://pypi.org/project/opencv-contrib-python/#files ? – Peter Badida Jul 24 '22 at 14:30
  • 1
    you could reproduce what you did in your own post, but not with python3.6 but 3.9 or 3.10. it'll download the same binary package, install it just the same. – Christoph Rackwitz Jul 24 '22 at 15:24