matplotlib crashing Python

后端 未结 5 1445
不思量自难忘°
不思量自难忘° 2021-01-13 16:21

I\'m new to Python and matplotlib. A simple script I wrote is crashing and I was able to reproduce the crash with the following code:

import matplotlib.pyplo         


        
相关标签:
5条回答
  • 2021-01-13 16:53

    For macOS, just make sure that

    ~/.matplotlib/matplotlibrc contains:

    backend: MacOSX
    

    You don't need the other backends unless you specifically want them. Alternatively, perhaps you can do:

    import matplotlib
    matplotlib.use("MacOSX")
    

    though I have not tested that.

    0 讨论(0)
  • 2021-01-13 16:57

    This could be issue with python 3.x

    I have tried with python 2.7 on my windows machine and it works perfectly fine!

    You can either downgrade your python to 2.7 or if you feel its too late to do why dont you give it a try to call close()

    Import matplotlib
    matplotlib.use('wxAgg')
    Import matplotlib.pyplot as plt
    # your scripts
    plt.close('all')
    
    0 讨论(0)
  • 2021-01-13 16:58

    You need to set the TkAgg backend explicitly. With the following code, the problem is resolved.

    import matplotlib
    matplotlib.use("TkAgg")
    from matplotlib import pyplot as plt
    

    Note that setting the TkAgg backend after importing pyplot does not work either; it crashes too. You need to set it before importing pyplot.

    0 讨论(0)
  • 2021-01-13 17:00

    I had a similar issue in OSX when I updated to Python 3.4. IDLE was also crashing and there was a warning telling me the version was unstable.

    I solved it by following the prompts and updating the version of Tcl/Tk (8.5.9) - http://www.python.org/download/mac/tcltk .

    0 讨论(0)
  • 2021-01-13 17:13

    I was having this issue, I thought it was some line in my code causing the bug, but in fact the very act of importing matplotlib.pyplot was killing my program. I solved it by first running it in verbose mode:

    python -v [programname].py

    This shows the last action the importer does before crashing. For me, the last line of this was:

    import 'PyQt5' # <_frozen_importlib_external.SourceFileLoader object at 0x000001F8EC9C0908>

    This suggested to me that the dependent library PyQt5 was causing issues, so I ran pip install PyQt5, and magically everything started working.

    0 讨论(0)
提交回复
热议问题