question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cv2 import error in docker image projectmonai/monailabel:0.4.0

See original GitHub issue

Describe the bug MONAI-Label Server cannot be executed in the current version of the monailabel docker container, because of an opencv import error.

To Reproduce

  1. Run docker container, tag 0.4.0, e.g. via: docker run -it --gpus all --network=host projectmonai/monailabel:0.4.0 bash
  2. Run: python -c "import cv2"

Error message This throws the following error message:

root@workstation:/opt/monai# python -c "import cv2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/conda/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/opt/conda/lib/python3.8/site-packages/cv2/__init__.py", line 175, in bootstrap
    if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
  File "/opt/conda/lib/python3.8/site-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
    py_module = importlib.import_module(module_name)
  File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/opt/conda/lib/python3.8/site-packages/cv2/mat_wrapper/__init__.py", line 33, in <module>
    cv._registerMatType(Mat)
AttributeError: partially initialized module 'cv2' has no attribute '_registerMatType' (most likely due to a circular import)

Environment As described above, I am using OOTB docker container projectmonai/monailabel:0.4.0.

Additional information For context, this error does not occur in the current monai-core docker image: projectmonai/monai:0.9.0.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

4reactions
SachidanandAllecommented, Jun 14, 2022

4.6.0.66 has some issue and conflicts with conda (not with regular python) so the current solution is

  • downgrade opencv-python-headless to previous 4.5.5.64 pip install opencv-python-headless==4.5.5.64
2reactions
SachidanandAllecommented, Jun 14, 2022
docker run --gpus all --rm -ti --ipc=host --net=host -v ~:/workspace projectmonai/monai:latest bash
python -c "import cv2" # OK

pip install opencv-python-headless
python -c "import cv2" # NOT OK
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in Running Docker image. Showing no module named ...
I am not able to run my script on docker as I am not able to run modules like cv2 , numpy ,...
Read more >
OpenCV Docker error "ImportError: libSM.so.6: cannot open ...
I am trying to run my deep learning model on docker. I am using OpenCV for some initial image processing. The problem is...
Read more >
cannot import OpenCV in a Docker container in Raspberry Pi
Seems to be just an issue with a Python package. Traceback (most recent call last): File "a.py", line 1, in <module> import cv2...
Read more >
GitLab Docker images
The GitLab Docker images are monolithic images of GitLab running all the necessary services in a single container. If you instead want to...
Read more >
Install OpenCV Docker Image on Ubuntu, MacOS or Windows
Guide to Install OpenCV 4.0 and 3.4.1 Docker Images on Ubuntu, MacOS, and Windows. The images also come preloaded with dlib.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found