【问题标题】:When executing exe file: ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected when executing exe file执行 exe 文件时:ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected when execution exe file
【发布时间】:2021-08-30 17:15:57
【问题描述】:

我使用 pyinstaller 创建了一个 .exe 文件。当我在 Pycharm 上运行它时,它运行良好。 但是当我尝试运行可执行文件时会发生错误。

这是完整的错误:

Traceback (most recent call last):
  File "DT_070621.py", line 397, in <module>
  File "DT_070621.py", line 315, in arquivos_saida
  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.
[11304] Failed to execute script 'DT_070621' due to unhandled exception!

但是当我检查 matplotlib 版本时,一切似乎都很好。

>>> import matplotlib
>>> matplotlib.__version__
'3.4.3'

我还检查了正在使用的后端:

>>> import matplotlib.pyplot as plt
>>> plt.get_backend()
'TkAgg'

我也尝试过像这样创建 .exe 文件:

pyinstaller --hidden-import=openpyxl --hidden-import=matplotlib --onefile DT_070621.py

但这并没有解决我的问题。

我还查看了this question,但它的描述似乎不完整,并且没有任何答案可以帮助我解决这个问题。

这是我脚本中的导入:

import xml.etree.ElementTree as ET
from xml.etree import ElementTree
import pandas as pd
from shapely.geometry import Point, Polygon
import numpy as np
import matplotlib.pyplot as plt
import os

发生了什么,我该如何解决?

【问题讨论】:

标签: python matplotlib pyinstaller


【解决方案1】:

添加--hidden-import pandas.plotting._matplotlib 解决了它。

【讨论】:

    猜你喜欢
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 2022-12-02
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多