diff --git a/pytools/graphviz.py b/pytools/graphviz.py
index 6e7c7485c83fb0d7e2e28117bb86c38021daf548..7d4ba9d83c21734d0fade4eb639340ea21a8e031 100644
--- a/pytools/graphviz.py
+++ b/pytools/graphviz.py
@@ -33,6 +33,7 @@ Dot helper functions
 
 import html
 import logging
+import os
 from typing import Optional
 
 
@@ -99,7 +100,7 @@ def show_dot(dot_code: str, output_to: Optional[str] = None) -> Optional[str]:
                                  "make sure it is in your $PATH.")
             supported_formats = proc.stderr.read().decode()
 
-            if " x11 " in supported_formats:
+            if " x11 " in supported_formats and "DISPLAY" in os.environ:
                 output_to = "xwindow"
             else:
                 output_to = "browser"