首页 > 解决方案 > 由于未处理的异常而无法执行脚本:选择默认后端“matplotlib”时需要使用matplotlib进行绘图

问题描述

我有一个.py显示历史股票曲线以在不同股票之间进行比较的程序,在 PyCharm 中运行它是毫无疑问的,但是当将其转换.py.exe文件或当此转换命中语句时df.plot,错误显示如下:

Failed to execute script ‘my_python_file’ due to unhandled exception: matplotlib is required for plotting when the default backend “matplotlib” is selected.

同样的转换方法适用于我的另一个.py显示计算器 GUI 的程序,运行它的文件没有任何问题exe,但不适用于这个显示股票曲线的程序。试pip install了好几个包,还是不行!期待高手的意见!

标签: pythonmatplotlib

解决方案


hello furas,

There are two steps to do the converting:
1.  pip install pysimplegui-exemaker
2.  python -m pysimplegui-exemaker.pysimplegui-exemaker

After the two steps, a GUI pops up where you can select the .py to make .exe.

and the traces:
Traceback (most recent call last):
  File "matplotlibDrawing.py", line 130, in <module>
    tsla_ningde.plot(kind='line',figsize=(8,5))
  File "pandas\plotting\_core.py", line 892, in __call__
  File "pandas\plotting\_core.py", line 1814, in _get_plot_backend
  File "pandas\plotting\_core.py", line 1754, in _load_backend
ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected.

推荐阅读