Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 and OpenCV have similar libraries; how to avoid conflict between the 2?

I have PyQt5 and OpenCV in the same conda virtual environment.

opencv-python==3.4.1.15    
PyQt5==5.10.1    

Whenever I run my PyQt5 app, I get many warnings like these:

objc[7992]: Class QCocoaPageLayoutDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0290) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f20). One of the two will be used. Which one is undefined.
objc[7992]: Class QCocoaPrintPanelDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0308) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f70). One of the two will be used. Which one is undefined.    
objc[7992]: Class QCocoaApplicationDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0010) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed480). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSApplication is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109adffc0) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed4d0). One of the two will be used. Which one is undefined.    
objc[7992]: Class QCocoaMenuLoader is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109adff70) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed570). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSImageView is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0330) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed660). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSStatusItem is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0380) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed6b0). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSOpenSavePanelDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0150) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed750). One of the two will be used. Which one is undefined.

What is the appropriate way to handle this?

like image 248
Alex Ryan Avatar asked Jul 16 '18 23:07

Alex Ryan


2 Answers

I solved the problem by uninstalling opencv with the GUI and installing the headless version:

pip uninstall opencv-contrib-python

pip install opencv-contrib-python-headless

The namedWindow function in opencv still works.

like image 171
Randy Westra Avatar answered Oct 20 '22 00:10

Randy Westra


In my case, I solved the problem removing opencv-python

pip3 uninstall opencv-python

and then installing opencv-headless

pip3 install opencv-python-headless

After that, my application run again.

like image 24
Moises Santana Pereira Avatar answered Oct 20 '22 00:10

Moises Santana Pereira