Launch zenity from the pyinstaller packed app fails on some systems #8916
-
Hello there, this problem is driving me nuts and I'm struggling with it since the last 2 weeks. I wrote a simple music player based on Gstreamer using customtkinter. Since the file open dialog that comes along with TKInter is really ugly, I decided to use zenity, if present on the system, and fall back to TKInter otherwise. This is used to pick up the audio file to be played. Everything works fine on my developing box. Running the original script and the pyinstaller packed version I have no problem. If I run the executable artifact on different systems it won't launch zenity and the "stderr" grabbed by the Here is my code: import subprocess
import os
ZEN_CMD = "zenity"
def __check_zenity__() -> bool:
try:
subprocess.run([ZEN_CMD, "-h"], capture_output=True, text=True)
return(True)
except:
return(False)
def openFileDialog(title = None, filter = None, initialdir = None):
if(__check_zenity__()):
return(__z_open__(**locals()))
else:
return(__tk_open__(**locals()))
def __z_open__(title = None, filter = None, initialdir = None):
cmd = [ZEN_CMD, "--file-selection"]
if(title is not None):
cmd.append('--title')
cmd.append(title)
if(initialdir is None):
initialdir = os.getcwd()
initialdir = os.path.join(initialdir, "")
cmd.append('--filename')
cmd.append(initialdir)
if(filter is not None):
# example: mp3 -> MP3 files: *.mp3
filetypes = [f"{str(x).upper()} files: *.{x}" for x in filter]
# Insert all the extension together as the first available filter
filetypes.insert(0, "Supported files: " + ' '.join(["*." + x for x in filter]))
# Append the "All files: *" at the end of filter
filetypes.append("All files: *")
for f in filetypes:
cmd.append("--file-filter")
cmd.append(f)
try:
result = subprocess.run(cmd,capture_output=True, text=True)
print(result)
return(result.stdout.strip())
except:
return(None)
def __tk_open__(title = None, filter = None, initialdir = None):
from tkinter import Tk
import tkinter.filedialog
filetypes = []
filetypes.append(("Supported files:", ' '.join(["*." + x for x in filter])))
for x in filter:
filetypes.append((f"{str(x).upper()} files", f"*.{x}"))
filetypes.append(("All files", "*.*"))
root = Tk()
root.withdraw()
f = tkinter.filedialog.askopenfilename(parent=root, initialdir = initialdir,
title = title,filetypes = filetypes)
if(len(f) == 0):
retFile = ""
else:
retFile = f
root.destroy()
return(retFile) This is the returning object from the subprocess call on a my developing PC:
This is what I get when running the program on a freshly installed Linux Mint 22 Cinnamon. I have verified that manually running the same command from the shell, open zenity with no errors
In particular this is the content of stderr: The rest of the app works flawlessly on every box: I can play the audio files giving them from the command line, but I can't open them when I run the app without arguments. Thanks in advance for your help! My dev environment: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If you want to run a system-installed program from the frozen application, you need to ensure that the subprocess uses only system libraries. Otherwise you might get various symbol conflicts, like the one you've shown above. You do that by resetting See |
Beta Was this translation helpful? Give feedback.
If you want to run a system-installed program from the frozen application, you need to ensure that the subprocess uses only system libraries. Otherwise you might get various symbol conflicts, like the one you've shown above. You do that by resetting
LD_LIBRARY_PATH
environment variable in the environment passed to your subprocess (or restoring it fromLD_LIBRARY_PATH_ORIG
, if available).See
https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#launching-external-programs-from-the-frozen-application
and
https://pyinstaller.org/en/stable/runtime-information.html#library-path-considerations