-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Matplotlib.get_backend()/matplotlib.use() cause NSException with Anaconda #13096
Comments
I've never had TkAgg work on my MacOSX machine either (though maybe it worked in 2.2.3 - I've not tried recently). |
Actually, the TKAgg backend does work both in 2.* and 3.0.2. I.e., this code is fine:
It appears to be just the call to |
So what backend is getting chosen? |
Run with |
@jklymak, TKAgg is selected before the script crashes. @anntzer, output when run with -Xfaulthandler:
|
If you print the result of |
Does the following diff modified lib/matplotlib/__init__.py
@@ -1376,10 +1376,13 @@ def get_backend():
See Also
--------
matplotlib.use
"""
+ val = dict.__getitem__(rcParams, 'backend')
+ if val is rcsetup._auto_backend_sentinel:
+ return 'unselected'
return rcParams['backend']
def interactive(b):
"""
solve the problem? |
@anntzer,
|
@tacaswell, that diff fixes it! |
Not to be a royal pain, but the proposed patch won't fix the issue if someone does |
Sorry, I should have provided more context with that diff, I just wanted to see if avoiding touching the OSX backend at all would avoid the problem, not as a fix to the problem. @moonshoes87 The fastest fix is to remove the conditional (as re-setting the backend to |
I am getting what I believe is the same error. @anntzer's description of the issue sounds apt, since I am using some eventloop code similar to IPython's. |
I guess in some sense my code is bugged. I should be using |
I ran into this issue debugging some issue Anaconda users reported. I can provide some examples which replicate the problem using a conda provided Python as well as Python from Python.org. The root cause seems to be that if The following script will terminate with an uncaught NSException using Python 3.7.2 from Python.org after pip installing matplotlib 3.0.2: import matplotlib
from matplotlib.backends import _macosx
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
fig = plt.figure() This is not entirely un-expected as the backend is switched in the middle of the script which end users should not be doing. The more surprising result is what @moonshoes87 reported, import matplotlib
matplotlib.get_backend()
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
fig = plt.figure() With a Python.org Python and matplotlib installed from the 3.0.2 wheel this will run fine because the wheel ships with a matplotlibrc file with |
I think master now works with the non framework build on macosx. I’ve never had Tkagg work though others report it working. Does tkagg really work if macosx is not imported? |
The following works on my machine using a conda provided Python as well as Python.org Python: import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
fig = plt.figure()
plt.plot([1,2,3])
plt.show() |
One final example example, the following will terminate with an uncaught exception on a non framework Python provided by conda despite the import matplotlib
try:
from matplotlib.backends import _macosx
except Exception as e:
print(e)
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
fig = plt.figure()
Removing the try/except block runs fine. |
I can confirm that error w/ 3.0.2. On master it runs fine, so I think (?) we've fixed this. Are you able to test the development version? Otherwise, it'll be available w/ 3.1 |
It also works on v3.0.x, though it emits the framework warning. So it'll also be in a bug fix release soon. |
I can confirm that the issues I explored are fixed in master. Thanks for the suggestion @jklymak. |
Closing because this is fixed on master. |
@jjhelmus how did you confirm that the issues were fixed in master? Did you build the Conda recipe with master? Because the new Conda matplotlib 3.0.3 package still has the issue. I searched the master branch commits for something like the patch @tacaswell mentioned, but couldn't find it there. Are we sure this has been fixed for the Conda + macOS case that this issue was about? Or is the issue in the Conda package somehow? |
3.0.3 was tagged off of the 3.0.x branch, not master. We got our book-keeping crossed on this, re-milestoning to where it is actually fixed. We should consider doing a 3.0.4 that fixes this issue + the pytest3.8 backports? |
Ah, I see, thanks for the clarification. Seeing as 3.1.0 is expected soon, I would be fine with skipping 3.0.4, just my 2ct. |
I could not solve this issue.
Tried it with "macOSX" It just doesn't work. My flask webapp crashes the moment it runs pip installed matplotlib version: |
Can you open a new issue with your exact error message? tk has serious issues on MacOS. Have you tried Qt? |
Sure. Will create it soon. I tried |
Install Qt? |
A bit new to this. Yeah, installed it and it still crashes. Here is the complete error message:
|
Bug report
Bug summary
The fix for #12362 appears to cause an NSException in matplotlib 3.0.2 with Anaconda Python.
Code for reproduction
Actual outcome
Expected outcome
I expected a figure to be created without crashing. This worked in matplotlib 2.2.3.
Matplotlib version
print(matplotlib.get_backend())
): TKAggMatplotlib was installed via conda using the default channel.
The text was updated successfully, but these errors were encountered: