在 parmap 上使用 pyinstaller 会导致 tkinter matplotlib 导入错误。为什么?

Using pyinstaller on parmap causes a tkinter matplotlib import error. Why?

更新

如果我尝试从 Pyinstaller 3.2 降级到 3.1,我会在尝试 运行 可执行文件时得到以下回溯。

我尝试按照此处所述将 --hidden-import=collect_submodules('pkg_resources._vendor') 添加到 pyinstaller,但没有效果。同样的错误。这似乎是由于 setuptools 的问题。我正在使用 26.0.0。许多消息人士称降级到 19.3 确实解决了这个问题,但我又回到了下面的问题。


我有一个 python 2.7 pyqt4 项目,我正在尝试使用 pyinstaller 将其转换为 .exe。我使用:

pyinstaller --additional-hooks-rir=. --clean --win-private-assemblies pipegui.py

pipegui.py 可以在 github here

上找到

我得到了一个可以运行的可执行文件,并且该应用程序似乎可以正常运行。 Here 是终端在 pyinstaller 冻结时吐出的内容。但是,当我 运行 我程序的特定部分时,应用程序崩溃了。它崩溃了,终端进入循环,不断输出下面相同的回溯,最上面的 "Poolworker-X" 不断递增:

如您所见,tkinter 受到牵连,尽管 "tkinter" 这个词没有出现在我的项目中(使用 pyqt4)。不过,我正在使用 matplotlib,根据讨论的答案 here and here 我已将以下内容添加到 pipegui.py 我的主要脚本的顶部:

    from Tkinter import * 
    import Tkinter
    import FileDialog

然而,这似乎是朝着错误的方向迈出了一步,因为在用这个(以及与以前相同的标志)冻结之后,我的可执行文件甚至无法打开,而是我得到了这个:

Here 是 pyinstaller 在冻结时几乎相同的输出。请记住,我所做的只是在上面添加这 3 个导入语句。就是这样。

我也试过 pyinstaller --additional-hooks=. --clean --win-private-assemblies --hidden-import=Tkinter pipegui.py 也没什么区别。我完全不明白为什么要导入 tkinter 会这样做。修复这个回溯会让我更接近解决另一个问题吗?

我在尝试所有这些之后才发现,我的可执行文件中唯一崩溃的部分是使用 parmap 多处理的部分。 类 使用 matplotlib 而不是 parmap 的工作正常。

所以请注意我的问题是如何修复第一个回溯以及为什么 matplotlib 和 tkinter 都出现在回溯中,尽管我的代码在崩溃发生时使用了 niether?

补充说明

Repiklis provided the solution in the comments. Further note that as of January 15 2017 Pyinstaller version 3.2.1 was released. I now use this and it solves this issue along with others like and this以前只能用开发者版解决。因此,如果您还没有升级到最新版本,我强烈建议您升级。