You are not logged in.

#1 2018-11-23 11:17:30

omega16
Member
Registered: 2018-11-23
Posts: 3

Python-Opencv [ERROR: recursion is detected during loading of "cv2"]

Hi, I don't know if this is a package issue or is a matter of Opencv, I was wanted to do a Arch actualization

sudo pacman -Syu

but I got a out of disc space error, so I did a

sudo pacman -Sc 

to delete cache files, then I did the actualization, now I can't import cv2 , I got the traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/usr/lib/python3.7/site-packages/cv2/__init__.py", line 79, in bootstrap
    import cv2
  File "/usr/lib/python3.7/site-packages/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/usr/lib/python3.7/site-packages/cv2/__init__.py", line 23, in bootstrap
    raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.


I got to /usr/lib/python3.7/site-packages/cv2/__init__.py do a copy and then try to solve by myself but I can't find how to solve, so i restored the copy :

'''
OpenCV Python binary extension loader
'''
import os
import sys

try:
    import numpy
    import numpy.core.multiarray
except ImportError:
    print('OpenCV bindings requires "numpy" package.')
    print('Install it via command:')
    print('    pip install numpy')
    raise

# TODO
# is_x64 = sys.maxsize > 2**32

def bootstrap():
    import sys
    if hasattr(sys, 'OpenCV_LOADER'):
        print(sys.path)
        raise ImportError('ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.')
    sys.OpenCV_LOADER = True

    DEBUG = False
    if hasattr(sys, 'OpenCV_LOADER_DEBUG'):
        DEBUG = True

    import platform
    if DEBUG: print('OpenCV loader: os.name="{}"  platform.system()="{}"'.format(os.name, str(platform.system())))

    LOADER_DIR=os.path.dirname(os.path.abspath(__file__))

    PYTHON_EXTENSIONS_PATHS = []
    BINARIES_PATHS = []

    g_vars = globals()
    l_vars = locals()

    if sys.version_info[:2] < (3, 0):
        from cv2.load_config_py2 import exec_file_wrapper
    else:
        from . load_config_py3 import exec_file_wrapper

    def load_first_config(fnames, required=True):
        for fname in fnames:
            fpath = os.path.join(LOADER_DIR, fname)
            if not os.path.exists(fpath):
                if DEBUG: print('OpenCV loader: config not found, skip: {}'.format(fpath))
                continue
            if DEBUG: print('OpenCV loader: loading config: {}'.format(fpath))
            exec_file_wrapper(fpath, g_vars, l_vars)
            return True
        if required:
            raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))

    load_first_config(['config.py'], True)
    load_first_config([
        'config-{}.{}.py'.format(sys.version_info[0], sys.version_info[1]),
        'config-{}.py'.format(sys.version_info[0])
    ], True)

    if DEBUG: print('OpenCV loader: PYTHON_EXTENSIONS_PATHS={}'.format(str(l_vars['PYTHON_EXTENSIONS_PATHS'])))
    if DEBUG: print('OpenCV loader: BINARIES_PATHS={}'.format(str(l_vars['BINARIES_PATHS'])))

    for p in reversed(l_vars['PYTHON_EXTENSIONS_PATHS']):
        sys.path.insert(0, p)

    if os.name == 'nt':
        os.environ['PATH'] = ';'.join(l_vars['BINARIES_PATHS']) + ';' + os.environ.get('PATH', '')
        if DEBUG: print('OpenCV loader: PATH={}'.format(str(os.environ['PATH'])))
    else:
        # amending of LD_LIBRARY_PATH works for sub-processes only
        os.environ['LD_LIBRARY_PATH'] = ':'.join(l_vars['BINARIES_PATHS']) + ':' + os.environ.get('LD_LIBRARY_PATH', '')

    if DEBUG: print('OpenCV loader: replacing cv2 module')
    del sys.modules['cv2']
    import cv2

    try:
        import sys
        del sys.OpenCV_LOADER
    except:
        pass

    if DEBUG: print('OpenCV loader: DONE')

bootstrap()

load_config_py3.py:

# flake8: noqa
import os
import sys

if sys.version_info[:2] >= (3, 0):
    def exec_file_wrapper(fpath, g_vars, l_vars):
        with open(fpath) as f:
            code = compile(f.read(), os.path.basename(fpath), 'exec')
            exec(code, g_vars, l_vars)


config-3.7.py

PYTHON_EXTENSIONS_PATHS = [
    '/build/opencv/src/build/lib/python3'
] + PYTHON_EXTENSIONS_PATHS

config.py

BINARIES_PATHS = [
    '/build/opencv/src/build/lib'
] + BINARIES_PATHS

I'm using opencv-3.4.4-1 with Python 3.7.1 , I think that maybe there and opencv problem (not of pacman or or mine) because of this posts

Note :
I already did a

 
sudo pacman -R opencv
sudo pacman -Sc 
sudo pacman -S opencv
 

but the problem still remains.

Offline

#2 2018-11-23 12:42:48

olk
Member
Registered: 2017-01-28
Posts: 10

Re: Python-Opencv [ERROR: recursion is detected during loading of "cv2"]

Offline

#3 2018-11-23 22:35:19

loqs
Member
Registered: 2014-03-06
Posts: 17,321

Re: Python-Opencv [ERROR: recursion is detected during loading of "cv2"]

Offline

#4 2018-11-24 00:16:46

omega16
Member
Registered: 2018-11-23
Posts: 3

Re: Python-Opencv [ERROR: recursion is detected during loading of "cv2"]

Thanks, I've already updated to  opencv-4.0.0-4 using  the downgrade guide as suggested on https://bugs.archlinux.org/task/60855 and it worked.

My question is, did doing it this way was inappropriate? I mean I ran

pacman -U https://archive.archlinux.org/packages/o/opencv/opencv-4.0.0-4-x86_64.pkg.tar.xz

In the future before version 4.0.0-4 comes out, I'll simply have to make partial updates to avoid going back to an earlier version, is there anything else I should be careful about?

Offline

Board footer

Powered by FluxBB