{"record":{"id":"7b3e4a2a88c3ebc7","repo":"xtekky/gpt4free","slug":"pystray-is-required-for-system-tray-support-insta","errorCode":null,"errorMessage":"pystray is required for system tray support. Install it with: pip install pystray pillow","messagePattern":"pystray 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":118,"sourceCode":"):\n    \"\"\"\n    Launch the g4f system tray application.\n\n    Parameters\n    ----------\n    port : int\n        Port for the API server (default 1337).\n    host : str\n        Bind host for the API server (default 0.0.0.0).\n    debug : bool\n        Enable verbose logging.\n    no_autostart : bool\n        If True, the API server is NOT started automatically on launch.\n    \"\"\"\n    try:\n        import pystray\n    except ImportError:\n        raise ImportError(\n            \"pystray is required for system tray support. \"\n            \"Install it with: pip install pystray pillow\"\n        )\n\n    from g4f.api import AppConfig, run_api\n\n    browser_url = f\"http://127.0.0.1:{port}\"\n\n    # ------------------------------------------------------------------ #\n    # Server management                                                    #\n    # ------------------------------------------------------------------ #\n    _server_thread: Optional[threading.Thread] = None\n    _server_running = threading.Event()\n\n    def _start_server():\n        nonlocal _server_thread\n        if _server_running.is_set():\n            return","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/tray.py#L100-L136","documentation":"g4f/tray.py raises this ImportError when the system-tray entry point tries to 'import pystray' and it is not installed. pystray is an optional dependency used to show the g4f tray icon and server controls, so it is not bundled with the base install.","triggerScenarios":"Invoking the tray launcher (g4f/tray.py's run function, e.g. via the GUI/tray entry point) in an environment where 'pip install pystray' was never run or pystray was uninstalled.","commonSituations":"Installing g4f without the GUI/tray extras; a venv created from a requirements list that omits pystray; running on a headless server where pystray was skipped intentionally.","solutions":["Install the missing dependency: pip install pystray pillow","If you do not need the tray icon, use the non-tray entry point (e.g. run the API directly via g4f.api) instead of g4f/tray.py","Add pystray and pillow to your project's requirements to keep the install reproducible"],"exampleFix":"# before\npython -m g4f.tray  # ImportError: pystray is required\n\n# after\npip install pystray pillow\npython -m g4f.tray","handlingStrategy":"try-catch","validationCode":"import importlib.util\n\nhas_pystray = importlib.util.find_spec(\"pystray\") is not None","typeGuard":null,"tryCatchPattern":"try:\n    from g4f.tray import run  # or the tray entry point\nexcept ImportError as e:\n    if \"pystray\" in str(e):\n        # degrade: start the API server without the tray icon\n        from g4f.api import run_api\n    else:\n        raise","preventionTips":["Install optional GUI extras up front: pip install pystray pillow","Declare pystray/pillow in requirements when the tray is used","On headless servers, use the API entry point instead of the tray"],"tags":["import-error","optional-dependency","tray","installation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}