简体   繁体   English

pyinstaller有时找不到Matplotlib后端TkAgg

[英]pyinstaller sometimes can't find Matplotlib backend TkAgg

I'm using pyinstaller to package a windows executable for our PyQT tool. 我正在使用pyinstaller打包我们的PyQT工具的Windows可执行文件。

pyinstaller.exe main.py --path path_to_pyqt_libs --distpath outputFolder --name toolName

4 out of 5 times, the tool can't find matplotlib backend TKagg: 5次中有4次,该工具找不到matplotlib后端TKagg:

19537 INFO:   Matplotlib backend "TkAgg": ignored
DLL load failed: The specified module could not be found.

The process still complete 'successfully' but I can't run the tool because of the missing library. 该过程仍然“成功”完成,但是由于缺少库,我无法运行该工具。 Occasionally (~20% of the time), the library is found ('added') and everything works fine. 偶尔(约20%的时间)会找到该库(“添加”),并且一切正常。 The same behavior occurs on 2 different machines with similar environment. 在具有相似环境的2台不同计算机上会发生相同的行为。

What drives me crazy is that it sometimes works without any changes. 使我发疯的是,有时它无需任何更改即可工作。

Any idea why this is happening and how I could solve this issue ? 知道为什么会发生这种情况以及如何解决这个问题吗?

Environment: 环境:

  • Windows 7 sp1 64bit Windows 7 SP1 64位
  • python 3.5.0 python 3.5.0
  • pyQt 5 pyQt 5
  • pyinstaller 3.2.1 pyinstaller 3.2.1
  • matplotlib 2.0.2 matplotlib 2.0.2

UPDATE: The following minimal code is sufficient to reproduce the error: 更新:以下最少的代码足以重现该错误:

#!/usr/bin/env python3

from PyQt5.uic import loadUiType

from matplotlib.backends.backend_qt5agg import (
    FigureCanvasQTAgg as FigureCanvas,
    NavigationToolbar2QT as NavigationToolbar)


if __name__ == '__main__':
    pass

If you got the same error doing this in a Python shell: 如果在Python shell中执行此操作时遇到相同的错误:

import matplotlib.backends._tkagg

Then you have to install the Visual C++ Redistributable Packages . 然后,您必须安装Visual C ++可再发行组件包 I had the exact same problem and install that solve it. 我有完全相同的问题,并安装可以解决它。

Also I had to do this hidden-import for avoid tkinter errors: 另外,我还必须执行此隐藏导入操作以避免tkinter错误:

--hidden-import='PIL._tkinter._finder

This answer was the solution 这个答案是解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM