【问题标题】:ModuleNotFoundError: No module named 'matplotlib.backends.backend_svg' when running exe from pyinstallerModuleNotFoundError:从 pyinstaller 运行 exe 时没有名为“matplotlib.backends.backend_svg”的模块
【发布时间】:2022-01-07 14:07:47
【问题描述】:

我想使用 pyinstaller onefile 将 python 文件编译为独立的 .exe 程序。运行python文件,一切正常,但运行.exe文件,却抛出异常

ModuleNotFoundError: 没有名为“matplotlib.backends.backend_svg”的模块

我正在使用schemdraw, 并且 schemdraw 使用 matplotlib。

因为我不希望 matplotlib 在每次导出 svg 时都打开一个窗口,所以我将后端“Agg”与 matplotlib 一起使用。

import matplotlib.backends.backend_tkagg
import matplotlib
matplotlib.use('Agg')

  • 我当然试过重新安装matplotlib
  • 使用而不是 pyinstaller --onefile <file> pyinstaller <file>
  • 我尝试将import matplotlib.backends.backend_tkagg 放在import matplotlip
  • 升级matplotlibpip install matplotlib --upgrade --user 基本上this post。但由于这不完全是我的问题,而且都没有奏效,所以我在这里问

提前致谢

【问题讨论】:

    标签: python python-3.x matplotlib pyinstaller


    【解决方案1】:

    除了 schemdraw 之外,你还需要使用 Matplotlib 吗?如果没有,您可以将 schemdraw 设置为直接绘制到 SVG:

    schemdraw.use('svg')
    

    那么它甚至不会通过 Matplotlib。

    【讨论】:

    • 不,我不必使用 Matplotlib。但是您能否链接文档或详细说明使用方法?在schemdraw.use('svg') 我找不到文档。谢谢
    • Documentation。与默认的 Matplotlib 后端工作相同;使用 Drawing.save() 或 Drawing.get_imagedata() 以字节形式获取 svg。
    猜你喜欢
    • 2021-03-05
    • 2017-05-19
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多