Opencv installation

Question: how to import opencv

I tried to download the opencv-python in packages then import it, but somehow it doesn’t work as I expected.

opencv-python
Version 4.7.0.72

import cv2

gives

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import cv2
  File "/home/runner/DASC2110-final-project-non-OOP/venv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/runner/DASC2110-final-project-non-OOP/venv/lib/python3.10/site-packages/cv2/__init__.py", line 111, in bootstrap
    load_first_config(['config.py'], True)
  File "/home/runner/DASC2110-final-project-non-OOP/venv/lib/python3.10/site-packages/cv2/__init__.py", line 109, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

If I use import opencv-python instead of import cv2, it gives SyntaxError: invalid syntax.
I have no idea how to solve it.

Add a config.py, it probably says where somewhere in the docs.

so I need to import os or re to rewrite the code from the package?

For some reason opencv doesn’t work on newer repls, you will have to fork an older repl that uses opencv. Try to fork this repl and paste your code in it: https://replit.com/@IanAtReplit/TextExtractionfromImage-Port

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.