PyInstaller generated .app file opens at terminal but not when double-clicked #8773
-
When I run Here is the # -*- mode: python ; coding: utf-8 -*-
import os.path
from pathlib import Path
from PyInstaller.compat import is_darwin, is_win
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
relative_site_packages_path = "venv/Lib/site-packages" if is_win else "venv/lib/python3.10/site-packages"
datas = [
(f"{relative_site_packages_path}/customtkinter", "customtkinter"),
(f"{relative_site_packages_path}/transformers", "transformers"),
(f"{relative_site_packages_path}/lightning", "lightning"),
(f"{relative_site_packages_path}/lightning_fabric", "lightning_fabric"),
(f"{relative_site_packages_path}/speechbrain", "speechbrain"),
(f"{relative_site_packages_path}/pyannote", "pyannote"),
(f"{relative_site_packages_path}/asteroid_filterbanks", "asteroid_filterbanks"),
(f"{relative_site_packages_path}/whisperx", "whisperx"),
(f"{relative_site_packages_path}/librosa", "librosa"),
("res", "res"),
("config.ini", "."),
(".env", "."),
]
hiddenimports = [
"huggingface_hub.repository",
"sklearn.utils._cython_blas",
"sklearn.neighbors.quad_tree",
"sklearn.tree",
"sklearn.tree._utils",
]
block_cipher = None
is_debug = True
if is_debug:
options = [("v", None, "OPTION")]
else:
options = []
a = Analysis(
["src/app.py"],
pathex=[relative_site_packages_path],
binaries=[],
datas=datas,
hiddenimports=hiddenimports,
hookspath=[],
hooksconfig={},
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)
macos_icon = "res/macos/icon.icns"
windows_icon = "res/windows/icon.ico"
exe = EXE(
pyz,
a.scripts,
options,
exclude_binaries=True,
name="Audiotext",
debug=is_debug,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=is_debug,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file="res/macos/entitlements.plist" if is_darwin else None,
icon=windows_icon if is_win else macos_icon,
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name="Audiotext",
)
app = BUNDLE(
coll,
name="Audiotext.app",
icon=macos_icon,
bundle_identifier="com.henestrosadev.audiotext",
version="2.3.0",
info_plist={
"NSPrincipalClass": "NSApplication",
"NSAppleScriptEnabed": False,
"NSHighResolutionCapable": True,
"NSMicrophoneUsageDescription": "Allow Audiotext to record audio from your microphone to generate transcriptions.",
}
) Here is the repo with the code (the |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 9 replies
-
This usually indicates that you are using some functionality that implicitly depends on full shell environment, which you get when you run your app from terminal, but not when application is ran from Finder. Usually this is debugged by wrapping your whole entry-point script into a try/except block and write the exception to a text file at fixed location.
I've also seen .app bundles crash because they were not built with windowed/noconsole bootloader variant (#7123 (comment)). I.e., for .app bundles, |
Beta Was this translation helpful? Give feedback.
-
I suspect you're in the same boat as #7459. If that's the case, you should be able to reproduce the issue by removing custom environment variables: env -i ./dist/Audiotext.app/Contents/MacOS/Audiotext If that's not the case then wrap your code in some try/except log error handling. import traceback
try:
main code here (including imports)
except:
with open("/Users/Shared/error.log", "w") as f:
f.write(traceback.format_exc()) |
Beta Was this translation helpful? Give feedback.
-
I was wrapping the code without the imports inside the
ffmpeg is indeed installed on my Mac, but when I run the |
Beta Was this translation helpful? Give feedback.
-
Thank you @rokm and @bwoodsend for your help! |
Beta Was this translation helpful? Give feedback.
-
As I said earlier, the
This is the code of the def load_audio(file: str, sr: int = SAMPLE_RATE):
try:
# Launches a subprocess to decode audio while down-mixing and resampling as necessary.
# Requires the ffmpeg CLI to be installed.
cmd = [
"ffmpeg",
"-nostdin",
"-threads",
"0",
"-i",
file,
"-f",
"s16le",
"-ac",
"1",
"-acodec",
"pcm_s16le",
"-ar",
str(sr),
"-",
]
out = subprocess.run(cmd, capture_output=True, check=True).stdout
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0 |
Beta Was this translation helpful? Give feedback.
You need to also set
IMAGEIO_FFMPEG_EXE
environment variable at the start of your program (or addsys._MEIPASS
toPATH
environment variable, althoughIMAGEIO_FFMPEG_EXE
should be preferable).