Skip to content

Showing an image opens a console #7789

@Vermylion

Description

@Vermylion

What did you do?

Tried opening an image using image.show() with a .pyw file.

What did you expect to happen?

Logically, no cmd console should pop up, as the file is no console.

What actually happened?

PIL opens up a console when launching image viewer, presumably Windows Viewer (default viewer).

What are your OS, Python and Pillow versions?

  • OS: Windows 10/11
  • Python: 3.12
  • Pillow: 10.2.0

To Replicate the Issue

Have a file with no console extension: main.pyw
Launch python file outside of an environment, IDE, or a console (cmd). Launch it, for example, from the Windows File Explorer.

from PIL import Image

img_path = 'your_image_path.png' # Replace with your image path

img = Image.open(img_path)

img.show()

Potential Solution

From what I've seen and understood, the issue is caused in ImageShow.py, show_file() line 116 with os.system(self.get_command(path, **options)). This line of code appears to be opening a new console if the file is ran with no console. However, it can be easily fixed by replacing os by subprocess: subprocess.call(self.get_command(path, **options), shell=True, creationflags=subprocess.CREATE_NO_WINDOW) (has been tested and works).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions