Opencv Errror even though installed

I am unable to get opencv-python to work on even though the packages are showing as installed. Receiving the following error:
File “/home/runner/OptimisticProudGenerics/venv/lib/python3.8/site-packages/cv2/”, line 109, in load_first_config
raise ImportError(‘OpenCV loader: missing configuration file: {}. Check OpenCV installation.’.format(fnames))
ImportError: OpenCV loader: missing configuration file: [‘’]. Check OpenCV installation.

any suggestions?

My test code looks like the following:

import cv2
import pathlib

# Step 0: Read Image from a file
file = pathlib.Path(__file__).parent.resolve() / input("Enter image name in same directory: ")
image1 = cv2.imread(str(file))

# Shows image on the screen until any button is pressed then closes windows
cv2.imshow('Hit any key to continue',image1)

# Step 1: Convert to Grey Image. Using cvtColor function of OpenCV. 
grey_img = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)

# Step 2: Invert Image. 
invert = cv2.bitwise_not(grey_img)

# Step 3: Blur image.
blur = cv2.GaussianBlur(invert, (21, 21), 0)

# Step 4: Invert Blurred Image.
invertedblur = cv2.bitwise_not(blur)

# Step 5: Convert to Sketch. 
sketch = cv2.divide(grey_img, invertedblur, scale=256.0)

# Step 6: Save Sketch. Read back in to verify saved file
filesave = file.with_name(str(pathlib.Path(file).stem) + '-sketch.jpg')
cv2.imwrite(str(filesave), sketch)
image = cv2.imread(str(filesave))

# Step 7: Display sketch.
cv2.imshow('Hit any key to exit', image)

Welcome to the community! I’m not familiar with this particular Python module but it appears that your installation of it may be corrupted. Try the following:
In shell, run poetry remove cv2; poetry add cv2.
If that doesn’t work, try pip install cv2.

1 Like

CoderElijah, Thank you for your suggestion. I have already done those things, both in the terminal and using the GUI package manager, as well as letting the template auto-install upon seeing the “import opencv-python” line in the code.

I did find an old thread that has a working solution, but it still needs addressing by the REPL team. If I fork a very old project with opencv, the fork will work. Any project created with recent templates fails.

Would you mind including the link to that thread since it solved your problem?

Sorry for me not being a big help but welcome to replit ask @MarkFuller. Hope you enjoy your time with us.

It will take me a while to find the discussion thread as I don’t have that handy. The discussion said to fork the following REPL that was an opencv example.

If I fork that REPL, delete all the code, and then paste all of my code inside, it works correctly.
If I start a new REPL it fails with an opencv configuration error.
I have let the “import opencv” auto install, but errors…
I have used GUI package manager to remove and reinstall opencv-python but it errors.

The only working solution has been to fork that old project, and hope that the old project never disappears.

I have used terminal and “pip install opencv-python” but still errors

For anyone else encountering this issue, you could try downgrading OpenCV version:

pip install opencv-python==

If the OpenCV package gets forecfully updated during installation of other packages, you can simply re-run the pip install command above.

1 Like