opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

ImportError: DLL load failed while importing cv2: The specified module could not be found.

Open NajetMed opened this issue 1 year ago • 7 comments

Expected behaviour

I'am trying to run a cod about document classification and I got this error i try to install the library via Anaconda but doesn't exist. import pandas as pd import numpy as np import tensorflow as tf import string import nltk import pathlib import os import cv2 import matplotlib.pyplot as plt from tensorflow.keras.utils import to_categorical from tensorflow.keras.metrics import TruePositives, FalsePositives, TrueNegatives, FalseNegatives, BinaryAccuracy, Precision, Recall, AUC

NajetMed avatar Apr 26 '24 14:04 NajetMed

Install OpenCV using Anaconda:

  • Open the Anaconda Prompt or Anaconda PowerShell.
  • Run the following command to create a new virtual environment (replace env_name with the desired name for your environment):

If the installation is successful, you should be able to import the cv2 module without any issues.

  1. Install OpenCV using pip: If the Anaconda approach doesn't work, you can try installing OpenCV using pip.

    pip install opencv-python
    

This command will install OpenCV and its dependencies using pip.

  1. Check the installation path: If you have multiple Python installations or environments on your system, make sure that you are importing the cv2 module from the correct environment or installation path.

  2. Try Reinstall OpenCV: If the above steps don't work, you can try uninstalling and reinstalling OpenCV.

imSanko avatar Apr 28 '24 01:04 imSanko

OpenCV team does not maintain Anacoda packages, pip packages only. Looks like your OpenCV installation is not complete or broken. You can trace OpenCV loading process by setting sys.OpenCV_LOADER_DEBUG = 1 before the library import.

asmorkalov avatar May 21 '24 06:05 asmorkalov

I was facing the same issue. I have python 3.11.7 with opencv 4.9.0. It was working fine until I started working with opencv and C++ in visual studio, which caused this problem. I don't know how the problem occurred, but it prevented me from working with python. I uninstalled visual studio and tried again, but the problem persisted. I resolved the issue by following these steps:

  • Check for Visual C++ Redistributable 2015 : Ensure it is installed on your system.
  • Check for Windows Media Feature Pack : Make sure it is installed, as it is essential for opencv.

if the above requirements are satisfied but the issue still persists, try reinstalling the opencv package:

pip uninstall opencv-python 

delete the cv2 folder inside the location where you installed python packages\Lib\site-packages\cv2 reinstall opencv using pip :

pip install opencv-python 

this method worked for me if it doesn't work for you, refer to this: #36 this might help you

AlexAtom022 avatar Jul 11 '24 10:07 AlexAtom022

OpenCV team does not maintain Anacoda packages, pip packages only. Looks like your OpenCV installation is not complete or broken. You can trace OpenCV loading process by setting sys.OpenCV_LOADER_DEBUG = 1 before the library import.

Also likely a duplicate of either https://github.com/opencv/opencv-python/issues/771 and/or https://github.com/opencv/opencv-python/issues/856

Avasam avatar Aug 01 '24 16:08 Avasam

I was facing the same issue. I have python 3.11.7 with opencv 4.9.0. It was working fine until I started working with opencv and C++ in visual studio, which caused this problem. I don't know how the problem occurred, but it prevented me from working with python. I uninstalled visual studio and tried again, but the problem persisted. I resolved the issue by following these steps:

* Check for **Visual C++ Redistributable 2015** : Ensure it is installed on your system.

* Check for **Windows Media Feature Pack** : Make sure it is installed, as it is essential for opencv.

The last bit is crucial, because I am running tiny11 which removes the Windows Media Feature Pack. Without you, I would not have found the solution, thank you 👍

nriemenschneider avatar May 15 '25 10:05 nriemenschneider

Maybe the Windows Media Feature Pack issue should be a core OpenCV issue to give a more helpful error message.

Avasam avatar May 15 '25 13:05 Avasam