Home > Back-end >  I cannot import python Package Aruco from OpenCV
I cannot import python Package Aruco from OpenCV

Time:07-24

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.

CodePudding user response:

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.

CodePudding user response:

aruco is a module from OpenCV's contrib collection of modules.

Make sure to have opencv-contrib-python installed, 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.

  • Related