-
Notifications
You must be signed in to change notification settings - Fork 864
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
Importing cv2 prevents matplotlib from working #386
Comments
Don't use PyQt and Multiple Qt versions shipped by different packages will not work properly. Just use one GUI library at a time. In this case you have two different Qt versions in use, another from This is also explained in the Installation and usage part of the README of this project:
PyQt and opencv-python will not work properly together because TL;DR Do not use multiple packages which ship with their own copy of Qt together. |
A possibly naive question, could the opencv-python depend on pyqt5 instead of bundling its own Qt? |
In theory maybe, but very hard or impossible to implement reliably. Qt and other OpenCV third party dependencies come from the C++ code and are determined during build time. This package would have to be built against a specific version of PyQt5 (which in turn would have to be modified to ship with Qt development headers to begin with) and linker should be somehow tricked to load Qt from the PyQt5 package during runtime. It would be a huge mess to implement and maintain since Python's packaging ecosystem does not understand anything about binary dependencies. Imho OpenCV should be able load Qt / GTK etc. during runtime (not possible currently) instead of having hard link time dependencies to those libraries. Then I could ship just the core and OpenCV could load compatible GUI backend if it's found on user's machine. However, this would require quite large rewrite to the OpenCV C++ code since this repository provides only a toolchain for packaging and publishing the OpenCV Python bindings binary and does not contain any actual OpenCV code. |
Would it be possible to wrap the functions in import functools
_tripped = False
def _wrapper_factory(func):
@functools.wraps(func)
def _wrapper(*args, **kwargs):
global _tripped
if not _tripped:
# do env setting logic
_tripped = True
return func(*args, **kwargs)
locals().update({k: _wrapper_factory(locals()[k]) for k in LIST_OF_QT_FUNCTION}) It isn't a great option, but it may keep some users from accidentally stepping into this trap... |
Thanks for the suggestion, I'll think about it. |
System information (version)
Detailed description
Hello,
i used to work with matplotlib and opencv normally until i installed PyQt, whenever i import cv2 in the same file as matplotlib, matplotlib fuctions don't work (i tried in terminal and pycharm)
here is an example of the code :
that's what i get :
i reported this ISSUE problem to matplotlib packagers but they said they cant do anything from their side.
another thing is that i am using cv2 for a small animation, whenever i execute the code it works normally but it prints this message :
Thank you.
The text was updated successfully, but these errors were encountered: