Opencv suddenly has importError

Question:
I’ve suddenly started getting errors with opencv when I run my Repl. Here’s the log

  File "/home/runner/Flixr-Subtitles/main.py", line 4, in <module>
    from funcs import *
  File "/home/runner/Flixr-Subtitles/funcs.py", line 5, in <module>
    import cv2 as cv
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

This was not an issue prior to a couple of weeks ago.

I noticed this template from @NuclearPasta0: https://replit.com/@NuclearPasta0/OpenCV-Python#pyproject.toml

Have already got these settings in place on my Repl and still get the error. Was there a change to system level packages that caused this issue maybe?

Hello, it seems that replit recently fixed a bug that previously necessitated a workaround, and now the defunct workaround is causing problems.

I have updated my template to fix this, and also saved some storage by only using the nix package. Please try the template now, or copy the .replit configuration to your repl.

3 Likes

This worked great for a few days until today/yesterday when it seems Replit may have made another update and I get a new error (without me having updated anything)

Traceback (most recent call last):
  File "/home/runner/Flixr-Creative-Server/main.py", line 1, in <module>
    import functools, os, cv2, openai, urllib.request, random, time
ImportError: /nix/store/dg8mpqqykmw9c7l0bgzzb5znkymlbfjw-glibc-2.37-8/lib/libc.so.6: version `GLIBC_2.38' not found (required by /nix/store/4ww0ykrgvp0syh8za5131ncy08h9gcbc-opencv-4.7.0/lib/python3.10/site-packages/cv2.cpython-310-x86_64-linux-gnu.so)

Hello, I have updated my template to fix this strange new bug.
It is just one modification:
change the channel variable in .replit to any channel below 23.11 (so, preferably 23.05, "stable-23_05").

I am not entirely sure what has changed to cause this error.
Observations:
The error does not occur when running program from the shell (or equivalently, using a run variable in .replit file).
I suspect something changes with the builtin library paths. In replit, there are many nix packages provided by default (from REPLIT_LD_LIBRARY_PATH), such as glibc. The glibc version or even path inside this library path does not change, however.

(Please mark a post as solution if it has solved your problem.)

2 Likes

Interestingly, using stable-23_11 works today. They must have fixed something overnight.

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