Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 tasks done
11philip22 opened this issue Jun 15, 2023 · 28 comments
Open
4 tasks done

Comments

@11philip22
Copy link

Hi,
I installed opencv-contrib-python 4.7.0.72 using pip for python 3.11.4 on Windows 10 x86-64
But when I run I get this exceptiom DLL load failed while importing cv2: The specified module could not be found.

Expected behaviour

I expect the module to import and not trow an error.

Actual behaviour

This exception gets trown

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python311\Lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Python311\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing cv2: The specified module could not be found.

Steps to reproduce

  • example code
    import cv2
  • operating system
    Windows 10, i7-12700H with Intel Iris Xe Graphics and a NVIDIA RTX A1000
  • architecture (e.g. x86)
    x86-64
  • opencv-python version
    opencv-contrib-python-4.7.0.72
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)
  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)
  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")
  • I'm using the latest version of opencv-python
@GenericAccount2
Copy link

I have exactly this issue.
Is there a simple way to see which DLL failed to load, that sounds like a natural starting point for investigation.

@GenericAccount2
Copy link

After some investigation I see it fails on init.py in the cv2 folder on the line native_module = importlib.import_module("cv2")
No idea why yet

@encouver
Copy link

Is there a solution to this?

@kker4m
Copy link

kker4m commented Sep 10, 2023

Same problem, is there a solution ?

@GenericAccount2
Copy link

The instructions are a little out of date, but I believe they would solve the issue
Go to Windows -> Settings -> Uninstall/Install Apps
Go to Optional Features
Go to Add button
Look for Windows Media Pack

@aBelnades
Copy link

@GenericAccount2 This was the solution. Thank you.

@GenericAccount2
Copy link

I think that OpenCV should consider updating their documentation.
This is a frustrating error to encounter, and if documentation is out of date, and cannot be followed, nobody is normally going to self-solve their issue.

@opencv-alalek
Copy link

No idea which documentation you want to read.

https://pypi.org/project/opencv-python/

Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found.?
A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.
Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack.
...

And this is a copy of top level README of this project:

https://github.com/opencv/opencv-python

@lanfengc
Copy link

In your Python environment, execute this code and install the required packages.
For example, I created a virtual environment with conda,
I executed "conda install numpy protobuf hdf5 cudnn cudatoolkit".
I don't know if "cudnn cudatoolkit" has to be installed. Since I compiled OpenCV with CUDA, I need to install it.

@dcarrion87
Copy link

dcarrion87 commented Feb 15, 2024

Trying to run https://github.com/cudawarped/opencv-python-cuda-wheels on python 3.11 on Windows Server compiled by @cudawarped and getting import DLL error. All DLLs seem to be there. Not an issue when using python 3.7 on the same system.

@cudawarped
Copy link

cudawarped commented Feb 15, 2024

Trying to run https://github.com/cudawarped/opencv-python-cuda-wheels on python 3.11 on Windows Server compiled by @cudawarped and getting import DLL error. All DLLs seem to be there. Not an issue when using python 3.7 on the same system.

This is not an officially supported release. Please raise an issue on that repo with more details regarding your setup and which wheel you are using and I'll take a look.

@dcarrion87
Copy link

@cudawarped solved as part of: #955

@201811017
Copy link

I have tried the solution of Windows Media pack and still I have the same issue. But i have the following paths in the environment variables:
image

@cudawarped
Copy link

cudawarped commented Mar 15, 2024

I have tried the solution of Windows Media pack and still I have the same issue

Use process monitor to track down the missing dll. See ImportError: DLL load failed while importing cv2: The specified module could not be found

@jason660519
Copy link

I got the same problem.

@fluviotect
Copy link

I have the same problem (Python 3.11)

@cudawarped
Copy link

cudawarped commented Mar 27, 2024

@jason660519 and @fluviotect when you ran process monitor which dll's couldn't it find?

@catequalsgood
Copy link

At least for me the issue seems to be __init__.cp311-win_amd64.pyd and __init__.pyd. For everything else Process Monitor eventually displays a SUCCESS-message.
I am using Windows 11 Enterprise, OpenCV 4.6.0 and Python 3.11.8. Using 3.10.14 does not change the behaviour.
I tried looking for the Windows Media Pack but is it neither offered as an optional feature nor does it show up as an installed feature. So maybe my issues is something completely different.

@cudawarped
Copy link

cudawarped commented Apr 10, 2024

@catequalsgood I am presuming you are using a script to parse the process monitor output which is how you managed to filter it down to only those two entries, making the result extreemly odd.

Specifically I can't understand why python would be outputing an error that it can't find all the dll's when it has found them.

@catequalsgood
Copy link

I was not using a script but I changed that and looked at the log again. I did indeed miss one. intl.dll also never shows SUCCESS.

@cudawarped
Copy link

You may find it much easier to parse the exported list, see https://forum.opencv.org/t/dll-load-failed-when-importing-a-self-built-cv2-library-in-python/16942/15

@catequalsgood
Copy link

The output seems equivalent. More DLLs like VERSION.dll are returned because only loading version.dll is successful. __init__.cp311-win_amd64.pyd as well as __init__.pyd are of course missing from the output. Leaving only intl.dll

@SubhamBurnwal-BiswaGames

this is such a growing issue.. I am unable to import cv2 for days and my whole project is stuck!

@cudawarped
Copy link

@SubhamBurnwal-BiswaGames Did you build it yourself? If so did you check for the missing dll using process explorer and if so what was missing?

@Raknash3
Copy link

Raknash3 commented May 5, 2024

I too was facing the same issue. I have python 3.11.7 in my conda env and I used conda to install opencv and I faced the same import error. I reinstalled the Visual C++ redistributables, checked if opencv package was present in anaconda and even then I couldn't solve the issue. Then I noticed that conda by default installs opencv 4.7 and the lastest version was opencv 4.9. So I used pip to install the latest release of opencv 4.8.1.78 and now I can import the cv2 module successfully.

@quyq
Copy link

quyq commented Jun 23, 2024

For me, gstream runtime dll are not in site-packages\cv2 folder. I'm using the way mentioned at here:, i.e. add following before import cv2:
import os
gst_root = os.getenv('GSTREAMER_1_0_ROOT_MSVC_X86_64', 'C:/gstreamer/1.0/msvc_x86_64/')
os.add_dll_directory(gst_root+'bin')
import cv2

@JLin-45655
Copy link

JLin-45655 commented Jul 13, 2024

I too was facing the same issue. I have python 3.11.7 in my conda env and I used conda to install opencv and I faced the same import error. I reinstalled the Visual C++ redistributables, checked if opencv package was present in anaconda and even then I couldn't solve the issue. Then I noticed that conda by default installs opencv 4.7 and the lastest version was opencv 4.9. So I used pip to install the latest release of opencv 4.8.1.78 and now I can import the cv2 module successfully.

I used Anaconda Navigator to install opencv and got version 4.6.6. Then I had this "DLL load failed while importing cv2" issue. I tried to use "Process Monitor" suggested by other link and found that "intl.dll" was not found. After seeing Raknash3's comment, I removed the opencv with Anaconda Navigator and tried "conda install -c conda-forge open.cv" and had 4.7.0 installed. Now it works. Thanks.

@sina-razaghi
Copy link

encountered this error on Windows 11 Enterprise N. To fix it, I installed the Media Feature Pack by going to Settings > System > Optional Features > Add an Optional Feature. If the issue persists after installing the Media Feature Pack, try reinstalling OpenCV."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests