Pyinstaller + Tkinter + Mac OS + TCL

时间:2018-10-26 20:56:48

标签: python tkinter tcl pyinstaller

所以我试图使用Tkinter将非常​​简单的Python代码编译成二进制。这是test1.py的代码:

import Tkinter as tk

counter = 0
def counter_label(label):
  counter = 0
  def count():
    global counter
    counter += 1
    label.config(text=str(counter))
    label.after(1000, count)
  count()


root = tk.Tk()
root.title("Counting Seconds")
label = tk.Label(root, fg="dark green")
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
root.mainloop()

然后我使用pyinstaller通过运行以下命令进行编译:

pyinstaller --onedir --windowed test1.py

这可以正常运行,并且可以按预期生成2个文件(Unix版本的.exe和app)。当我单击应用程序文件时,它在启动时崩溃-我什么也没看到。如果我单击其他文件(.exe)样式-它会打开一个新的终端窗口,最终我收到以下错误消息:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/pip-install-MgS374/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
  File "lib-tk/Tkinter.py", line 39, in <module>
  File "/private/var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/pip-install-MgS374/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 546, in load_module
ImportError: dlopen(/var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/_MEIJX4TS8/_tkinter.so, 2): Library not loaded: @loader_path/Tcl
  Referenced from: /var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/_MEIJX4TS8/_tkinter.so
  Reason: no suitable image found.  Did find:
    /var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/_MEIJX4TS8/Tcl: not a file
    /private/var/folders/0t/1b6bbpcj52xdthkg2d6g2sr40000gn/T/_MEIJX4TS8/Tcl: not a file
test1 returned -1
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

该如何解决?我认为这与在Mac OS的Python版本上安装TCL有关。我在网络上看到了不同的潜在解决方案,但不幸的是,它们都没有起作用。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

看起来这是pyinstaller中的一个已知错误。

https://github.com/pyinstaller/pyinstaller/issues/1350