{"record":{"id":"384fe5623ac19997","repo":"xtekky/gpt4free","slug":"pillow-is-required-for-system-tray-support-instal","errorCode":null,"errorMessage":"pillow is required for system tray support. Install it with: pip install pystray pillow","messagePattern":"pillow is required for system tray support\\. Install it with: pip install pystray pillow","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"g4f/tray.py","lineNumber":204,"sourceCode":"    menu = pystray.Menu(\n        pystray.MenuItem(\"Open in Browser\", on_open_browser, default=True),\n        pystray.Menu.SEPARATOR,\n        pystray.MenuItem(server_label, on_toggle_server, enabled=server_enabled),\n        pystray.Menu.SEPARATOR,\n        pystray.MenuItem(\"Show logs\", lambda: on_open_browser(\"/logs\")),\n        pystray.Menu.SEPARATOR,\n        pystray.MenuItem(\"Quit\", on_quit),\n    )\n\n    icon_image = _make_icon()\n    if icon_image is None:\n        # Fallback: 1×1 transparent image (pystray still works, icon may be blank)\n        try:\n            from PIL import Image\n\n            icon_image = Image.new(\"RGBA\", (1, 1))\n        except ImportError:\n            raise ImportError(\n                \"pillow is required for system tray support. \"\n                \"Install it with: pip install pystray pillow\"\n            )\n\n    tray_icon = pystray.Icon(\n        name=\"g4f\",\n        icon=icon_image,\n        title=\"g4f AI Server\",\n        menu=menu,\n    )\n\n    # Auto-start the server unless opted out\n    if not no_autostart:\n        _start_server()\n\n    tray_icon.run()\n\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/tray.py#L186-L222","documentation":"g4f/tray.py raises this ImportError only in the fallback path: _make_icon() returned None (no bundled icon image could be built), so the code tries to create a 1x1 transparent PNG with PIL, and 'from PIL import Image' fails because pillow is not installed. pystray alone is not enough — an icon image needs pillow.","triggerScenarios":"Running the tray with pystray installed but pillow missing, AND the normal icon source unavailable (custom icon not found/not writable), so the 1x1 fallback is attempted.","commonSituations":"Installing pystray without pillow; environments where the icon asset path is broken (partial install, read-only dir) so _make_icon() returns None; CI containers with trimmed image libraries.","solutions":["Install pillow: pip install pystray pillow (the error message asks for both)","If _make_icon() returning None is itself unexpected, verify the g4f installation is complete (reinstall: pip install --force-reinstall g4f)","Run without the tray icon via the plain API entry point if an icon is not needed"],"exampleFix":"# before\npip install pystray  # pillow still missing -> fallback ImportError\n\n# after\npip install pystray pillow","handlingStrategy":"try-catch","validationCode":"import importlib.util\n\nhas_pillow = importlib.util.find_spec(\"PIL\") is not None","typeGuard":null,"tryCatchPattern":"try:\n    icon_image = Image.new(\"RGBA\", (1, 1))\nexcept ImportError:\n    # run tray with a generated icon file or skip the icon entirely\n    pass","preventionTips":["Install pystray AND pillow together as the message instructs","Verify optional imports in a startup smoke test for GUI deployments","Provide a writable custom icon path so the 1x1 fallback is never needed"],"tags":["import-error","optional-dependency","pillow","tray","fallback"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}