Missing config-3.py and config-3.8.py during installation from source

Hello,

I’m messing up when trying to install openCV from sources.

System: Ubuntu 18.04
OpenCV Version: 4.5.2 (latest)
Python: Python 3.8 and 3.9 (via anaconda)

Tutorial followed - How to install OpenCV 4.5 with CUDA 11.2 in Ubuntu 20.04 · GitHub

I’ve followed above tutorial, using anaconda python.

    Isaac@MSI:~/opencv-4.5.2/build/python_loader$ python setup.py install
    running install
    running bdist_egg
    running egg_info
    writing opencv.egg-info/PKG-INFO
    writing dependency_links to opencv.egg-info/dependency_links.txt
    writing requirements to opencv.egg-info/requires.txt
    writing top-level names to opencv.egg-info/top_level.txt
    reading manifest file 'opencv.egg-info/SOURCES.txt'
    writing manifest file 'opencv.egg-info/SOURCES.txt'
    installing library code to build/bdist.linux-x86_64/egg
    running install_lib
    running build_py
    creating build/bdist.linux-x86_64/egg
    creating build/bdist.linux-x86_64/egg/cv2
    copying build/lib/cv2/load_config_py2.py -> build/bdist.linux-x86_64/egg/cv2
    copying build/lib/cv2/config.py -> build/bdist.linux-x86_64/egg/cv2
    copying build/lib/cv2/load_config_py3.py -> build/bdist.linux-x86_64/egg/cv2
    copying build/lib/cv2/__init__.py -> build/bdist.linux-x86_64/egg/cv2
    byte-compiling build/bdist.linux-x86_64/egg/cv2/load_config_py2.py to load_config_py2.cpython-39.pyc
    byte-compiling build/bdist.linux-x86_64/egg/cv2/config.py to config.cpython-39.pyc
    byte-compiling build/bdist.linux-x86_64/egg/cv2/load_config_py3.py to load_config_py3.cpython-39.pyc
    byte-compiling build/bdist.linux-x86_64/egg/cv2/__init__.py to __init__.cpython-39.pyc
    creating build/bdist.linux-x86_64/egg/EGG-INFO
    copying opencv.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying opencv.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying opencv.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying opencv.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying opencv.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    zip_safe flag not set; analyzing archive contents...
    cv2.__pycache__.__init__.cpython-39: module references __file__
    creating 'dist/opencv-4.5.2-py3.9.egg' and adding 'build/bdist.linux-x86_64/egg' to it
    removing 'build/bdist.linux-x86_64/egg' (and everything under it)
    Processing opencv-4.5.2-py3.9.egg
    removing '/home/isaac/anaconda3/envs/cv/lib/python3.9/site-packages/opencv-4.5.2-py3.9.egg' (and everything under it)
    creating /home/isaac/anaconda3/envs/cv/lib/python3.9/site-packages/opencv-4.5.2-py3.9.egg
    Extracting opencv-4.5.2-py3.9.egg to /home/isaac/anaconda3/envs/cv/lib/python3.9/site-packages
    opencv 4.5.2 is already the active version in easy-install.pth

    Installed /home/isaac/anaconda3/envs/cv/lib/python3.9/site-packages/opencv-4.5.2-py3.9.egg
    Processing dependencies for opencv==4.5.2
    Searching for numpy==1.20.1
    Best match: numpy 1.20.1
    Adding numpy 1.20.1 to easy-install.pth file
    Installing f2py script to /home/isaac/anaconda3/envs/cv/bin
    Installing f2py3 script to /home/isaac/anaconda3/envs/cv/bin
    Installing f2py3.9 script to /home/isaac/anaconda3/envs/cv/bin

    Using /home/isaac/anaconda3/envs/cv/lib/python3.9/site-packages
    Finished processing dependencies for opencv==4.5.2

But when trying to import cv2 and check that everything works, this error arrise:

    (cv) isaac@MSI:~/opencv-4.5.2/build/python_loader$ python
    Python 3.9.4 (default, Apr  9 2021, 16:34:09)
    [GCC 7.3.0] :: Anaconda, Inc. 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 "/home/isaac/opencv-4.5.2/build/python_loader/cv2/__init__.py", line 102, in <module>
        bootstrap()
      File "/home/isaac/opencv-4.5.2/build/python_loader/cv2/__init__.py", line 63, in bootstrap
        load_first_config([
      File "/home/isaac/opencv-4.5.2/build/python_loader/cv2/__init__.py", line 60, in load_first_config
        raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
    ImportError: OpenCV loader: missing configuration file: ['config-3.9.py', 'config-3.py']. Check OpenCV installation.
    >>> exit()

I’ve not found so many discussions with config-3.py or any other variant related with the lines above. I’ve just found the solution of using pip install --upgrade opencv-python which was something I was trying to avoid

Am I missing sth? Is there a way to debug the line 60 error and not install opencv-pyhton

welcome.

I would recommend discarding that “tutorial”.

ignore anything that has superfluous steps, such as a python virtualenv, or installing a ton of random libraries you might not even need.

work with official documentation.

tl;dr:

  • get the sources (git clone, checkout a version tag)
  • start cmake or cmake-gui
  • cmake: configure until it works, disable modules that cause trouble
  • cmake: generate build files
  • build (make)
  • install, maybe

Thanks for your reply. I’ll try to do it again from scratch… but the cmake and build process of openCV is still a pass in the tutorial… and is where I’m getting stuck. I don’t think the problem come from installing libraries which might be also related with CUDA.


I’ll do it again, but I would appreciate knowing which are the cmake parameters to generate this config-3.9.py or config-3.py files
And also, the purpose of them… as I haven’t found the answer by myself

Same problem here:

OpenCV loader: missing configuration file: ['config-3.9.py', 'config-3.py']. Check OpenCV installation.

  File "C:\OpenCV\OpenCV_build\python_loader\cv2\__init__.py", line 109, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
  File "C:\OpenCV\OpenCV_build\python_loader\cv2\__init__.py", line 112, in bootstrap
    load_first_config([
  File "C:\OpenCV\OpenCV_build\python_loader\cv2\__init__.py", line 181, in <module> (Current frame)
    bootstrap()

I have no idea, why it is not acepting Python3.9

When configuring cmake what does the output say about your python version?
I suspect that I have a similar issue. Where opencv creates a build for the wrong version even when you specify the python version to build for.

Here is an example from my cmake output as you can see from the python3 interpreter I am trying to build opencv for python3.10, however cmake detects it as a version 3.8 and thus installs it accordingly. Thus you get the config-3.x is missing errors.

I know that this thread is kind of old, but could you check if you get the same behavior during building?

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.18)
    Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.18)
    numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.5)
    install path:                lib/python2.7/dist-packages/cv2/python-2.7

  Python 3:
    Interpreter:                 /usr/local/bin/python3.10 (ver 3.8.10)
    Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.10)
    numpy:                       /home/marius/.local/lib/python3.10/site-packages/numpy/core/include (ver 1.19.5)
    install path:                /home/marius/.local/lib/python3.10/site-packages/cv2/python-3.8

  Python (for build):            /usr/bin/python2.7

For people struggeling with this, this fixed it for me: Building OpenCV for an alternative python install