OPENCV package is not usable (probably very easy to fix, please help)

Question:

Hi I am trying to learn how to use OPENCV.
I have this very simple script, and it gives a traceback. I have uninstalled OPENCV several times and re installed it and the same message appears. Really not sure if it’s a mistake I made or if REPLIT is maybe not compatible with OPENCV?

Repl link/Link to where the bug appears:
POTATOCOUNT 2 - Replit

SCRIPT AND TRACEBACK

HERE IS THE SCRIPT

import cv2

# Load the image
image_path = 'your_image.jpg'
image = cv2.imread(image_path)

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Show the grayscale image
cv2.imshow('Grayscale Image', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()

HERE IS THE TRACEBACK

 python3 main.py
Traceback (most recent call last):
  File "/home/runner/POTATOCOUNT-2/main.py", line 1, in <module>
    import cv2
  File "/home/runner/POTATOCOUNT-2/.pythonlibs/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/runner/POTATOCOUNT-2/.pythonlibs/lib/python3.10/site-packages/cv2/__init__.py", line 111, in bootstrap
    load_first_config(['config.py'], True)
  File "/home/runner/POTATOCOUNT-2/.pythonlibs/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.
exit status 1

OpenCV takes some extra config, so use the template:
https://replit.com/@scottatreplit/Python-OpenCV

1 Like

Thanks!
Sounds very helpful, but indeed something very strange happens between replit and openCV.

I have downloaded (forked? not sure if that’s the right word) as suggested the template (and named it POTATOCOUNT3), and the example provided works well.

However when i replace the provided code with my own script i get a frightening Qt error.

My URL: main.py - POTATOCOUNT3 - Replit

MY SCRIPT

import cv2 as cv

# Load the image
image_path = 'IMAGEPATATE.jpg'
image = cv.imread(image_path)

# Convert the image to grayscale
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)

# Show the grayscale image
cv.imshow('Grayscale Image', gray)
cv.waitKey(0)
cv.destroyAllWindows()

MY TRACEBACK

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/runner/POTATOCOUNT3/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

SIGABRT: abort
PC=0x7fb3d24adbaa m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4dded0, 0xc000068cf0, 0x4111d8)
    runtime/cgocall.go:154 +0x5b fp=0xc000068cc0 sp=0xc000068c88 pc=0x406bfb
main._Cfunc_pry_eval_file(0x555556d60750, 0x555556d26a00, 0x1, 0x555556d78900, 0xc000000000)
    _cgo_gotypes.go:562 +0x48 fp=0xc000068cf0 sp=0xc000068cc0 pc=0x4db848
main.Python.EvalFile.func5(0x555556d60750, 0x555556d26a00, 0xc0000c6170, 0x0, 0x0, 0x555556d78900, 0x0)
    github.com/replit/prybar/languages/python3/main.go:92 +0x6d fp=0xc000068d28 sp=0xc000068cf0 pc=0x4dd1ad
main.Python.EvalFile(0x7fff6e506b8e, 0x7, 0xc0000c6170, 0x0, 0x0, 0x0)
    github.com/replit/prybar/languages/python3/main.go:92 +0x275 fp=0xc000068de8 sp=0xc000068d28 pc=0x4dc475
main.(*Python).EvalFile(0x605980, 0x7fff6e506b8e, 0x7, 0xc0000c6170, 0x0, 0x0, 0xc0000ad110)
    <autogenerated>:1 +0x65 fp=0xc000068e28 sp=0xc000068de8 pc=0x4dda25
github.com/replit/prybar/utils.Language.EvalFile(0x53b5a8, 0x605980, 0x7fff6e506b78, 0x12, 0x7fff6e506b8e, 0x7, 0xc0000c6170, 0x0, 0x0, 0x43d1e5)
    github.com/replit/prybar/utils/language.go:86 +0x9e fp=0xc000068e80 sp=0xc000068e28 pc=0x4da21e
github.com/replit/prybar/utils.DoCli(0x53b5a8, 0x605980)
    github.com/replit/prybar/utils/utils.go:67 +0x3c5 fp=0xc000068f68 sp=0xc000068e80 pc=0x4daca5
main.main()
    github.com/replit/prybar/languages/python3/generated_launch.go:7 +0x39 fp=0xc000068f88 sp=0xc000068f68 pc=0x4db059
runtime.main()
    runtime/proc.go:225 +0x256 fp=0xc000068fe0 sp=0xc000068f88 pc=0x439c16
runtime.goexit()
    runtime/asm_amd64.s:1371 +0x1 fp=0xc000068fe8 sp=0xc000068fe0 pc=0x46b981

rax    0x0
rbx    0x6
rcx    0x7fb3d24adbaa
rdx    0x0
rdi    0x2
rsi    0x7fff6e504360
rbp    0x7fff6e5045a0
rsp    0x7fff6e5043d8
r8     0x0
r9     0x7fff6e504360
r10    0x8
r11    0x246
r12    0x555557218808
r13    0x7fff6e504770
r14    0x7fff6e504708
r15    0x7fff6e504778
rip    0x7fb3d24adbaa
rflags 0x246
cs     0x33
fs     0x0
gs     0x0
repl process died unexpectedly: exit status 2

Note that whatever I sent on that topic will need modification to work on the new modules-based python repls due to changes in structure of the hidden files but if you learn to configure replit like I said at the end, maybe you can get to a solution to this ancient issue, before I can even retry

Coincidentally, I’ve fixed a similar package, so I decided to make another template, for OpenCV. The other template looks a bit outdated.
Use this template.
A bonus is that it will have python 3.10 instead of 3.8, and it uses more modern replit stuff, including better code intelligence.

2 Likes

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