【问题标题】:Pyinstaller with Tkinter Matplotlib numpy scipyPyinstaller 与 Tkinter Matplotlib numpy scipy
【发布时间】:2016-06-14 17:07:47
【问题描述】:

我正在使用 Pyinstaller(在使用 py2exe 很长时间之后)将我的 REAL.py 文件转换为 .exe。我使用 Anaconda 制作了在我的计算机上完美运行的 .py 文件。但是当我制作 .exe 文件时,它没有显示错误,并且在 dist\REAL 文件夹中创建了一个应用程序。但是当我运行 .exe 文件时,控制台会立即打开和关闭。

理想情况下,它应该显示一个 GUI 窗口并接受输入并使用它们来制作绘图。当我运行 REAL.py 文件时它会这样做。我正在使用 Anaconda 附带的 Tkinter、Matplotlib、numpy、scipy。

编辑:我尝试运行简单的代码来检查与 matplotlib 的兼容性:

将 matplotlib.pyplot 导入为 plt

plt.plot([1,2,3,4])

plt.ylabel('一些数字')

plt.show()

同样的问题仍然存在。打开控制台窗口,然后关闭,但没有给出任何情节。

【问题讨论】:

  • 我遇到了类似的问题。您可能想尝试的一件事是使用“--debug”标志作为 pyinstaller 的参数 - 它可以帮助您确定具体的故障是什么。

标签: python-2.7 anaconda pyinstaller


【解决方案1】:

我在 py2exe 中找到了解决方案。以下是与 Tkinter Matplotlib numpy scipy 导入一起使用的 setup.py 文件:

from distutils.core import setup
import py2exe

from distutils.filelist import findall
import matplotlib

opts = {"py2exe": {
    "packages" : ['matplotlib'],
    "includes": ['scipy', 'scipy.integrate', 'scipy.special.*','scipy.linalg.*'],
         'dll_excludes': ['libgdk-win32-2.0-0.dll',
                            'libgobject-2.0-0.dll',
            'libgdk_pixbuf-2.0-0.dll']
                     }
           }

setup(
      windows = [{'script': "with_GUI.py"}], zipfile = None,
      options= opts,
      data_files = matplotlib.get_py2exe_datafiles()
     )

但这给了我一些错误,说两个文件存在版本冲突。所以我改变了这两个文件,即。 dist/tcl/tcl8.5/init.tcl(第 19 行)和 dist/tcl/tk8.5/tk.tcl(第 18 行)。就我而言,我将版本从 8.5.15 更改为 8.5.18。我通过查看错误日志中错误指定的路径找到了这两个文件的位置。然后 .exe 工作得很好。

我希望这会有所帮助。

【讨论】:

  • 谢谢 Girish - 你能告诉我你是如何使用 setup.py 文件的吗?我只是想弄清楚如何使用 pyinstaller 命令来完成这项工作。
【解决方案2】:

在调用 pyinstaller 时尝试使用 --hidden-import=matplotlib。例如,您可以在命令提示符下键入:

Pyinstaller --hidden-import=matplotlib your_filename_here.py

您也可以尝试在其中使用 tkinter。

Pyinstaller --hidden-import=matplotlib --hidden-import=tkinter your_filename_here.py

【讨论】:

    猜你喜欢
    • 2020-07-17
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 2018-08-08
    • 2015-12-10
    • 2012-10-10
    • 2018-01-11
    相关资源
    最近更新 更多