Repository: rootpy/rootpy

Issue:
Exception on import when not forwarding X11
Dear developers,

I believe I'm experiencing a bug when trying to use rootpy over SSH. Simply importing
```Python
from rootpy.plotting import Hist
```
results in an exception:
```Python
WARNING:ROOT.TUnixSystem.SetDisplay] DISPLAY not set, setting it to :pts/0:S.8
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/__init__.py", line 12, in <module>
    from .legend import Legend
  File "/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py", line 318, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/legend.py", line 8, in <module>
    from .box import _Positionable
  File "/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py", line 318, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/box.py", line 5, in <module>
    from .utils import canvases_with
  File "/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py", line 318, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/utils.py", line 7, in <module>
    from .canvas import _PadBase
  File "/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py", line 318, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/canvas.py", line 186, in <module>
    class Pad(_PadBase, QROOT.TPad):
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/utils/module_facade.py", line 84, in __getattr__
    result = sup.__getattr__(key)
  File "/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/utils/quickroot.py", line 71, in __getattr__
    libname, symbol))
RuntimeError: Unable to load libGui (required by TPad)
```
The problem does not occur if I connect with `ssh -Y`, but I would expect rootpy be usable also without GUI.

I'm using rootpy 1.0.0 installed with pip, Python 3.5.3, ROOT 6.10.04 with Scientific Linux 6.5.


Discussion:
I confirm I can reproduce this with ROOT 6.10.04 (only received the warning in earlier ROOTs). Will fix! Thanks for reporting!

Resolving patch:
diff --git a/rootpy/utils/quickroot.py b/rootpy/utils/quickroot.py
--- a/rootpy/utils/quickroot.py
+++ b/rootpy/utils/quickroot.py
@@ -65,6 +65,12 @@ def __getattr__(self, symbol):
                     if Load(libname) == 0:
                         log.debug("Loaded {0} (required by {1})".format(
                             libname, symbol))
+                    elif lib == 'Gui':
+                        # Possibly no X11 forwarding
+                        log.debug("Unable to load {0} (required by {1}). "
+                                  "Putting ROOT in batch mode.".format(
+                            libname, symbol))
+                        ROOT.gROOT.SetBatch(True)
                     else: # pragma: no cover
                         raise RuntimeError(
                             "Unable to load {0} (required by {1})".format(


Test patch: