I'm trying to use pyinstaller to create a basic Mac app using tkinter. The file itself, saved under the name example.py, is just
from tkinter import Tk,Label
window = Tk()
window.title("My Window")
lbl = Label(window, text="Hello World")
lbl.grid(column=0, row=0)
window.mainloop()
Very simple. Now
pyinstaller example.py --onefileĀ --windowed
produces an app bundle, but I'm unable to run the program from the terminal using
./dist/example.app/Contents/MacOS/example
due to the the error message
ModuleNotFoundError: No module named '_tkinter'
The spec file looks like this, where I've edited to include tkinter as a hidden import.
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['pyinstaller_basic'],
pathex=['/Users/fishbacp/Desktop/Python_May_2021'],
binaries=[],
datas=[],
hiddenimports=['tkinter'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='example',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
app = BUNDLE(exe,
name='example.app',
icon=None,
bundle_identifier=None)
Now I create the app using
pyinstaller example.spec example.py --onefile --windowed
Still, I get the same error message when trying to run the app from the terminal.
I'm using Python 3.9 on a Mac running Big Sur.