--- a/hdf_compass/compass_viewer/viewer.py
+++ b/hdf_compass/compass_viewer/viewer.py
@@ -16,8 +16,9 @@
 Defines the App class, along with supporting infrastructure.
 """
 # Must be at the top, to ensure we're the first to call matplotlib.use.
-import matplotlib
-matplotlib.use('WXAgg')
+import matplotlib, os
+mplbackend = 'WXAgg' if os.getenv('DISPLAY') else 'Agg'
+matplotlib.use(mplbackend)
 
 import traceback
 import sys
