Opencv error cv2

I am trying to deploy an application that use opencv but i am encountering this error

i already tried to modify my nix file

see nix file

{ pkgs }: {
  deps = [

Hey, @dragonchild870!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

Hey, @dragonchild870! Welcome to the forums!

Running OpenCV requires some extra configuration. Because of this, the staff have released a template that has everything configured and OpenCV installed here:
Hope this helps!


can you teach me how to install opencv properly only? i already check the template but there are a lot of things that i dont need there i just need the opencv only

this is my repl

Hi @dragonchild870 !
What is wrong with the template I mentioned earlier? You could delete the code in if you don’t want that, and replace it with your own code (but don’t change replit.nix or .replit).

1 Like

well i dont really have problem with it i just want to adapt it with my own setup, i dont use venv and python is 3.10 but the template is using 3.9 and older so if i can only install opencv properly thats enough for me, i want to gain understanding how to properly troubleshoot it

Try running

curl -s | bash -s

in the Shell of the repl. Make sure you take note of the Nix packages before entring the command in case they disappear.
@ShaneAtReplit could the template be updated to the latest version of Python and the Python template (the venv folder etc).

@dragonchild870 The command allows the repl to take up less space, as well as updating the structure to the current Python repl. Made by a Jr. Mod on this forum. I have used it myself many times, works like a gem. It uninstalls packages though, so install cv2 afterwards maybe?

1 Like

what happen in my situation was i installed opencv then after that its looking for like the screenshot i shared so what should i do next to fix that like is there something i need to change in nix file like this ?{ pkgs }: {
deps = [
} as much as possible i only need the openCV like i want to learn how to properly fix it without using the template i dont have any problem with the template i just dont want to rely on the template

Maybe try using the Nix modules used in the template?

IIRC, you have to explicitly add some extra configuration file somewhere, which is why Replit staff have just provided that template instead.

1 Like

The configuration for this might be in replit.nix, where it makes a library path that includes libGL.

{ pkgs }: {
  deps = [
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Neded for pandas / numpy
      # Needed for pygame
      # Needed for matplotlib
      # Needed for opencv-python
      pkgs.libGL  # <- new in OpenCV template
    PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
    LANG = "en_US.UTF-8";

The current official python template requires no nix dependencies and does not set an env variable here (so it might be hard to configure a new repl). The older python templates use prybar instead of python directly.

i have a question so i used the template and resolve everything but last problem i have is how can run it with streamlit? this is the file whenever i press the run button it just say run it with command ‘streamlit run’ which i already setup in the file below its working fine but how about you need to add new package? how can you configure it? like for example i want to use streamlit with it how can i configure it?
its also throwing error /usr/bin/env: ‘./python3’: No such file or directory when i try to run streamlit run in shell

disableInstallBeforeRun = true

# The command that runs the program.
run = "streamlit run --server.port 8080"

# The primary language of the repl. There can be others, though!
language = "python3"
# The main file, which will be shown by default in the editor.
entrypoint = ""
# A list of globs that specify which files and directories should
# be hidden in the workspace.
hidden = ["venv", ".config", "**/__pycache__", "**/.mypy_cache", "**/*.pyc"]

# Specifies which nix channel to use when building the environment.
channel = "stable-21_11"

# Per-language configuration: python3
# Treats all files that end with `.py` as Python.
pattern = "**/*.py"
# Tells the workspace editor to syntax-highlight these files as
# Python.
syntax = "python"

  # The command needed to start the Language Server Protocol. For
  # linting and formatting.
  start = ["pyls"]

# The command to start the interpreter.
  args = [
    "\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ",

# The environment variables needed to correctly start Python and use the
# package proxy.
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"

# Enable unit tests. This is only supported for a few languages.
language = "python3"

# Add a debugger!
support = true

  # How to start the debugger.
  transport = "localhost:0"
  startCommand = ["dap-python", ""]

    # How to communicate with the debugger.
    dapTcpAddress = "localhost:0"

    # How to tell the debugger to start a debugging session.
    command = "initialize"
    type = "request"

      adapterID = "debugpy"
      clientID = "replit"
      clientName = ""
      columnsStartAt1 = true
      linesStartAt1 = true
      locale = "en-us"
      pathFormat = "path"
      supportsInvalidatedEvent = true
      supportsProgressReporting = true
      supportsRunInTerminalRequest = true
      supportsVariablePaging = true
      supportsVariableType = true

    # How to tell the debugger to start the debuggee application.
    command = "attach"
    type = "request"

      logging = {}

# Configures the packager.
# Search packages in PyPI.
language = "python3"
# Never attempt to install `unit_tests`. If there are packages that are being
# guessed wrongly, add them here.
ignoredPackages = ["unit_tests"]

  enabledForHosting = false
  # Enable searching packages from the sidebar.
  packageSearch = true
  # Enable guessing what packages are needed from the code.
  guessImports = true

Run the file normally…? Not working?