matplotlib在带有TkAgg后端的macOS上的plt.show()中崩溃 [英] matplotlib crashes in plt.show() on macOS with TkAgg backend

查看:532
本文介绍了matplotlib在带有TkAgg后端的macOS上的plt.show()中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该脚本在for循环中运行,每次迭代调用plt.plot(),然后在循环调用plt.show()之后-崩溃(屏幕冻结,需要强制重新启动).崩溃之前或之后均未显示错误消息. IMO,这不是内存问题.

The script runs in a for loop, every iteration calls plt.plot() and after looping calls plt.show() - and crashes (screen freezes and need to force restart). No error message is presented before or after crashing. IMO, this is not a memory issue.

与从shell/PyCharm IDE运行脚本相同.

Same if I run the script from shell / PyCharm IDE.

有趣的观点:

  1. 我过去在相同的Mac和相同的配置上多次运行过此脚本. 唯一相关的是几天前我已经更新了操作系统.
  2. 当我在调试模式下运行脚本且停止点在"plt.show()"中时-没有崩溃,并且脚本在不显示图的情况下结束.
  3. 运行脚本时,将打开一个带有"python" -ish图标的小窗口.当我按下它时,什么也没有发生.
  1. I've ran this script many times in the past on the same Mac and same configuration. The only thing that could be relevant is that I've updated my OS few days ago.
  2. When I run the script in a debug mode with stopping point in "plt.show()" - and no crashing and scripts ends without showing the plot.
  3. When running the script, a small window with "python"-ish icon opens. When I press it nothing happens.

我已经尝试在此处此处-没有成功.

I've tried following many other reported issues here, here, and here - with no success.

MacOS版本:Mojave 10.14.6

MacOS version: Mojave 10.14.6

我无法共享代码和数据,但为了轻松重现该问题-尝试运行以下简单代码:

I can't share the code and the data, but to easily reproduce the problem - try running this simple code:

>>> import matplotlib
>>> matplotlib.use("TkAgg")
>>> from matplotlib import pyplot as plt
>>> plt.plot(range(10))
[<matplotlib.lines.Line2D object at 0x1141069e8>]
>>> plt.show()

Mac崩溃(冻结并需要重新启动).

And the Mac crushes (freezes and need restart).

包装:

matplotlib 3.0.3 py37h54f8f79_0
numpy 1.16.2 py37hacdab7b_0
numpy-base 1.16.2 py37h6575580_0
pyqt 5.9.2 py37h655552a_2
pyqt5 5.13.0 pypi_0 pypi scikit学习0.20.3 py37h27c97d8_0
scipy 1.2.1 py37h1410ff5_0

matplotlib 3.0.3 py37h54f8f79_0
numpy 1.16.2 py37hacdab7b_0
numpy-base 1.16.2 py37h6575580_0
pyqt 5.9.2 py37h655552a_2
pyqt5 5.13.0 pypi_0 pypi scikit-learn 0.20.3 py37h27c97d8_0
scipy 1.2.1 py37h1410ff5_0

*conda info*

     active environment : base
    active env location : /Users/nancy/anaconda3
            shell level : 1
       user config file : /Users/nancy/.condarc
 populated config files : /Users/nancy/.condarc
          **conda version : 4.7.11**
    conda-build version : 3.17.8
         **python version : 3.7.3.final.0**
       virtual packages : 
       base environment : /Users/nancy/anaconda3  (writable)
           channel URLs : http://statgen.org/wp-content/uploads/Softwares/pyplink/osx-64
                          http://statgen.org/wp-content/uploads/Softwares/pyplink/noarch
                          https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/nancy/anaconda3/pkgs
                          /Users/nancy/.conda/pkgs
       envs directories : /Users/nancy/anaconda3/envs
                          /Users/nancy/.conda/envs
               **platform : osx-64**
             **user-agent : conda/4.7.11 requests/2.21.0 CPython/3.7.3 Darwin/18.7.0 OSX/10.14.6**
                UID:GID : 501:20
             netrc file : None
           offline mode : False

推荐答案

根据 ImportanceOfBeingErnest 的评论,Apple不会就像Tkinter(TkAgg后端)一样,所以我需要将后端更改为"Qt5Agg"

According to ImportanceOfBeingErnest comment, Apple doesn't like Tkinter (TkAgg backend) so I needed to change the backend to 'Qt5Agg'

import matplotlib  
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt

这篇关于matplotlib在带有TkAgg后端的macOS上的plt.show()中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆