Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #9027

The issue has reported that a PyInstaller application does not have a Python instance as sys.executable - it has the application.

https://pyinstaller.org/en/stable/runtime-information.html

When a normal Python script runs, sys.executable is the path to the program that was executed, namely, the Python interpreter. In a frozen app, sys.executable is also the path to the program that was executed, but that is not Python

This means that

Pillow/src/PIL/ImageShow.py

Lines 178 to 185 in ef0bab0

executable = sys.executable or shutil.which("python3")
if executable:
subprocess.Popen(
[
executable,
"-c",
"import os, sys, time; time.sleep(20); os.remove(sys.argv[1])",
path,

will not be able to delete the image, and might inadvertently launch the application a second time.

Using a check from https://pyinstaller.org/en/stable/runtime-information.html, this PR ignores sys.executable if in a PyInstaller application. python3 might still be used.

@hugovk hugovk merged commit 8cf8b0d into python-pillow:main Jun 25, 2025
164 of 171 checks passed
@radarhere radarhere deleted the imageshow branch June 25, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show method caused an error on macOS when app is packed with PyInstaller

2 participants