-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
In 3.0.0 backend cannot be set if 'get_backend()' is run first #12362
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
Comments
I can't reproduce. Are you doing this from inside an interactive shell? Just running the above as a script I get the expected outcome on both master and v3.0.0 |
The same result occurs when I run the code within the Python interpreter or as a script. One difference is that if I run it as an executable: Here is the full matplotlib version info:
|
I can reproduce this with matplotlib 3.0.0 It's pretty strange that the warning complains about pyplot being imported without it being imported anywhere. Here the If using master, the problem does not occur. In both cases, Also when creating a conda environment without matplotlib,
and then running the code, the warning does not occur: Does conda do something to the matplotlib package, which it shouldn't? The |
Perhaps conda still ships a matplotlibrc with a backend: set? dunno. |
Ok let appart conda, how can it be that if you So what's the purpose of this line? matplotlib/lib/matplotlib/__init__.py Lines 876 to 880 in d5a4eda
|
This line throws me the following error if I import matplotlib inside PyCharm. |
@Kaushalya This sounds like a different issue, especially if it's working correctly in the command line. Note that PyCharm does a lot of crazy stuff with matplotlib internally (seen from all the results in their source code) so it may also be an issue with PyCharm only. If you think this to be a matplotlib issue (i.e. if you can reproduce this outside of PyCharm), I would suggest to open a new issue about it, including all details and full traceback. |
Any updates on this issue? Or is this something that should be raised with the Anaconda people instead? |
Given that the issue does not occur when matplotlib is installed via |
@moonshoes87 The issue is that we moved to an run-time fallback mechanism to sort resolve what GUI framework to use. Internally we set the backend to a sentinal to indicate that the fall-back / discovery code needs to run, however we do not want to return that to the users (for reasons of type stability) or to return a placeholder string (as it is not a real backend) so when you call Given the other constraints, I am not sure we can fix this for you. I suggest that you either setup a I am a bit confused about why this is only a problem in anaconda (them shipping a |
@tacaswell I don't see how this is conda's fault. I have no idea what matplotlibrc they ship, but I should be able to run the above code w/ no matplotlibrc. |
The correct fix IMO is what I proposed in #11600 (comment), which is to make use() succeed even if the backend has already been "set", as long as the event loop did not start yet. |
However we can not know the 'current backend' until we do the fallback process.
Do we have good handle on when each of the event loops gets started / checking it is started? I think we need to be cautious or more than just if the loop is running, but if input_hook has been set up. |
We have get_running_interactive_framework() which is supposed to check just that. |
I don't think we defer the imports long enough, if you have the rcparams set to Qt5, then even though the event loop will not have started yet you will not be able to switch to Qt4. In principle I agree it sounds good, but I am worried about it only working sometimes. |
In that specific case you'll get an ImportError, which is just fine with me. |
Bug report
Bug summary
In my code, I need to check whether the matplotlib backend has already been set. If it has not been set, I need to then set it to 'WXAgg'. In matplotlib 2.*, I was able to do this, but in matplotlib 3.0.0 it fails.
Code for reproduction
Actual outcome
With matplotlib 3.0.0:
Expected outcome
With matplotlib 2.2.3:
Matplotlib version
print(matplotlib.get_backend())
):The text was updated successfully, but these errors were encountered: