none
Can't use opencv-python package in windows container (Windows Server 2016 Standard) RRS feed

  • Question

  • I run the following container to test my opencv-python environment on Windows Server 2016.

    docker run -i --rm python:2.7-windowsservercore

    (the [python:2.7-windowsservercore] image is an official python image base on microsoft/windowsservercore)

    and in the interacive console, I got the opencv-python installed by:

    pip install opencv-python

    after this finished, I test the opencv-python package by:

    python -c "import cv2"

    but I got the following error:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Python\lib\site-packages\cv2\__init__.py", line 9, in <module>
        from .cv2 import *
    ImportError: DLL load failed: The specified module could not be found.

    then I installed python-2.7.13 on the host(not container side), input the same pip install commands, and test python -c "import cv2" again, it won't report this error. I wonder if there are some DLL missing in the container which existing on the host? What package or software should I install in the container to fix the error?

    Saturday, September 9, 2017 3:46 AM

Answers

  • Hey there mangobowl (nice name),

    opencv requires ancient Video for Windows, Microsoft AVI, and Microsoft ACM Audio support, which microsoft/windowservercore does not ship with.

    I was able to resolve the issue by adding the missing files, but we're in undocumented territory. You can't rely on OpenCV functionality that may touch VfW/AVI/ACM as those libraries are not guaranteed to work at all.

    OK, warning out of the way, here's what you need to do.

    Copy the following files from your host into your container's \System32 folder:

    • msacm32.dll
    • avifil32.dll
    • avicap32.dll
    • msvfw32.dll


    Let us know how it goes.


    • Proposed as answer by WithinRafaelMVP Saturday, September 9, 2017 9:24 PM
    • Edited by WithinRafaelMVP Saturday, September 9, 2017 9:25 PM Formatting
    • Marked as answer by mangobowl Thursday, September 21, 2017 12:02 PM
    Saturday, September 9, 2017 9:24 PM

All replies

  • Hey there mangobowl (nice name),

    opencv requires ancient Video for Windows, Microsoft AVI, and Microsoft ACM Audio support, which microsoft/windowservercore does not ship with.

    I was able to resolve the issue by adding the missing files, but we're in undocumented territory. You can't rely on OpenCV functionality that may touch VfW/AVI/ACM as those libraries are not guaranteed to work at all.

    OK, warning out of the way, here's what you need to do.

    Copy the following files from your host into your container's \System32 folder:

    • msacm32.dll
    • avifil32.dll
    • avicap32.dll
    • msvfw32.dll


    Let us know how it goes.


    • Proposed as answer by WithinRafaelMVP Saturday, September 9, 2017 9:24 PM
    • Edited by WithinRafaelMVP Saturday, September 9, 2017 9:25 PM Formatting
    • Marked as answer by mangobowl Thursday, September 21, 2017 12:02 PM
    Saturday, September 9, 2017 9:24 PM
  • Thanks a lot!

    I also found that DLLs missing by the depends.exe tool, and because I used 32-bit python, so I also copied the 32-bit compatible DLLs to SysWOW64 folder, it worked at last! and as you said, some function won't work, but it's enough for me.


    • Edited by mangobowl Thursday, September 21, 2017 12:03 PM
    Thursday, September 21, 2017 1:40 AM
  • Cool! If you could mark that post as the answer, that'll help close this out and be helpful for those searching the forums.
    Thursday, September 21, 2017 3:32 AM
  • Hey Mangobowl,

    is there any chance you could post what DLLs you had to move to the SysWOW64 folder? I've moved the the dll files suggested by Rafael to /Windows/System32 but I'm still getting the dll load failed error

    Thursday, October 5, 2017 10:30 PM