-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
qt imports do not pick defaults properly #4912
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
Conversation
…where a Qt related file was imported, but not set as the current backend.
We are going to need comments from those who use PySide to make sure all is kosher here. I am a little weary about this change. We are, in effect, guessing the user's intent. Perhaps it makes sense to inspect |
@WeatherGod I think you mean wary not weary 😉 I don't expect there to be a qt module imported when we enter I am ok with this change. Currently this is causing pain for any qt5 users who import I don't expect this to cause any problems for pyside users. attn @mfitzp |
@@ -47,8 +58,19 @@ | |||
# No ETS environment or incompatible so use rcParams. | |||
if rcParams['backend'] == 'Qt5Agg': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By this point I think we are gaurenteed that QT_RC_MAJOR_VERSION
is defined, we should switch on that instead of having the conditional import logic again.
What is the scenario where you are importing qt_compat directly, but with a backend set differently than what you want? I can only imagine two scenarios. 1) someone using qt_compat.py as a compatibility shim, completely ignoring matplotlib, or 2) someone who made a specialized backend that is Qt-based. In both of these situations, it points to a limitation in the design of qt_compat.py, but also I would have expected other Qt modules to have been imported by then (but I admit that that isn't guaranteed). Some people have suggested that qt_compat.py get turned into its own stand-alone project, but that is obviously outside the scope here. Sorry for rambling, I am just keeping in mind one of the tenets from PEP20: "in the face of ambiguity, resist the temptation to guess". |
The counter is that we are already guessing (by having the else blocks On Wed, Aug 12, 2015, 6:09 PM Benjamin Root [email protected]
|
True enough. How about putting in a warning?
|
+1 on adding a warning On Thu, Aug 13, 2015, 12:21 AM Benjamin Root [email protected]
|
I ran into this scenario with two separate cases, the first is in implementing a pure-Qt backend (no Agg!) and the second (more important to us) is more complicated... We have a module that when imported by our users will initialize matplotlib to recognize our data types. If we are operating in a headless (no display) environment, then we also set the backend to Agg (we have users that will run scripts both interactively and in batches and they requested this feature in our setup and it makes our nightly tests happier). Additionally we have some plot widgets that derive from the Qt matplotlib FigureCanvas. We also generate our documentation by explicitly introspecting the user API (this allows us to make sure the entire API is documented). The simple process of introspection imports both of these files. Importing one sets the backend to Agg, the other imports a widget (which isn't used), but in doing so it causes 'qt_compat' to be imported, which wants to ultimately import a non-existant PyQt4. |
I am convinced this should be merged once the comments are addressed. |
Apologies for the slow response (in the last stages of writing up my thesis) but I agree with the merge once the duplicate logic is removed. I think the move towards Qt5 by default is sensible since that is now the base API. The following block (not touched by this commit) means that the environment variable is only used when the major version number of the API from the environment matches that of the rcParam. In practise this means the environment variable only works to switch Qt4 versions (since Qt4 is the only one with >1 API). Otherwise it will silently be ignored:
I suggest we add another warning at the bottom of this? |
Marked as not a blocker as this as I am comfortable putting out RC1 without this fixed but it should done before the final release. |
@jrevans Ping, any update on this? |
Just a little change proposition from the jrevans commit : I have PyQt5 and PyQt4 installed at the same time, and both are used by different applications with matplotlib. With this change, all applications should work correctly if rcParams is not set. Line 31: else:
# A different backend was specified, but we still got here because a Qt
# related file was imported. This is allowed, so lets try and guess
# what we should be using.
if "PyQt5" in sys.modules:
# PyQt5 is actually used.
QT_RC_MAJOR_VERSION = 5
else:
# This is a fallback
QT_RC_MAJOR_VERSION = 4 Line 63: else:
# A different backend was specified, but we still got here because a Qt
# related file was imported. This is allowed, so lets try and guess
# what we should be using.
if "PyQt5" in sys.modules:
# PyQt5 is actually used.
QT_API = rcParams['backend.qt5']
else:
# This is a fallback
QT_API = rcParams['backend.qt4'] |
It's done. Here is the commit : jrevans@2a23a63 I don't find how adding it on the actual pull request. |
Please make a new pr, it is the easiest way. On Thu, Sep 17, 2015, 10:06 JGoutin [email protected] wrote:
|
@JGoutin Which branch from your fork should I be looking at? |
master branch |
Can you move that to a feature branch and open a pull request against mpl On Thu, Sep 24, 2015, 02:37 JGoutin [email protected] wrote:
|
You can find the pull request here : #5134 |
Replaced by #5134 |
This fixes an error where PyQt4 would always be selected in the case where a Qt related file was imported, but not set as the current backend.
This will essentially be a bit more forgiving when a Qt related file (ie. a matplotlib file that uses 'qt_compat.py') is imported when the backend is set to something other than 'Qt5Agg' or 'Qt4Agg'.
This addresses an issue in #4897.