Tkinter 与泡菜。 pyinstaller可执行文件问题

Tkinter with pickle. Pyinstaller executable file problem

我正在尝试在 (MacOS) 上创建可执行应用程序。该应用程序无法运行。

from tkinter import *
import pickle
root=Tk()
root.geometry("200x200")
test={"test"}
with open('test.pkl', 'wb') as f:
    pickle.dump(test, f)
filename='test.pkl'
try:
    model = pickle.load(open(filename, 'rb'))
    Label(text='loaded',fg="red").pack()
except:
    Label(text='An error occurred.',fg="red").pack()
root.mainloop()

航站楼: pyinstaller --onefile --windowed Yourfile.py

我找到了替代解决方案,但没有找到 Pyinstaller。 我使用 Pyinstaller 而不是 py2applet

第 1 步:-转到终端

pip3 install py2app

第 2 步:

py2applet --make-setup yourfile.py
Wrote setup.py

rm -rf build dist 

第 3 步:-配置您的安装文件。

APP = ['yourfile.py']
DATA_FILES = ["test.pkl"]
OPTIONS = {'argv_emulation': False,}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

第 4 步:-转到终端,然后;

python setup.py py2app -A

您的应用程序将在“dist”文件中创建。

如果您需要更多信息,请查看 https://py2app.readthedocs.io/en/latest/tutorial.html