prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `rootpy/utils/quickroot.py`
  Content:
  ```
  1 """
  2 Quickly load ROOT symbols without triggering PyROOT's finalSetup().
  3 The main principle is that appropriate dictionaries first need to be loaded.
  4 """
  5 from __future__ import absolute_import
  6 
  7 import ROOT
  8 
  9 from .. import log; log = log[__name__]
  10 from .module_facade import Facade
  11 
  12 __all__ = []
  13 
  14 
  15 root_module = ROOT.module._root
  16 if hasattr(root_module, 'LookupCppEntity'):  # pragma: no cover
  17     lookup_func = 'LookupCppEntity'
  18 else:  # pragma: no cover
  19     lookup_func = 'LookupRootEntity'
  20 
  21 # Quick's __name__ needs to be the ROOT module for this to be transparent.
  22 # The below is one way of obtaining such a function
  23 # First determine the ROOT version without triggering PyROOT's finalSetup()
  24 Quick = eval('lambda symbol: module._root.{0}(symbol)'.format(lookup_func),
  25              ROOT.__dict__)
  26 
  27 _gSystem = Quick("gSystem")
  28 Load = _gSystem.Load
  29 
  30 # It is not vital to list _all_ symbols in here, just enough that a library
  31 # will be loaded by the time it is needed.
  32 SYMBOLS = dict(
  33     Hist='TH1 TGraph TGraphAsymmErrors',
  34     Tree='TCut TTree',
  35     Gui='TPad TCanvas',
  36     Graf='TLegend TLine TEllipse',
  37     Physics='TVector2 TVector3 TLorentzVector TRotation TLorentzRotation',
  38     Matrix='TMatrixT',
  39     RooStats='RooStats RooMsgService',
  40     RooFit='RooFit RooWorkspace',
  41 )
  42 
  43 # Mapping of symbols to libraries which need to be loaded
  44 SYMBOLS_TO_LIB = dict(
  45     (sym, lib) for lib, syms in SYMBOLS.items() for sym in syms.split())
  46 
  47 # If you encounter problems with particular symbols, add them to this set.
  48 SLOW = set("".split())
  49 
  50 
  51 @Facade(__name__, expose_internal=False)
  52 class QuickROOT(object):
  53     def __getattr__(self, symbol):
  54         if symbol in SLOW:  # pragma: no cover
  55             log.warning(
  56                 "Tried to quickly load {0} which is always slow".format(symbol))
  57 
  58         lib = SYMBOLS_TO_LIB.get(symbol, None)
  59         if lib:
  60             # Load() doesn't cost anything if the library is already loaded
  61             libname = "lib{0}".format(lib)
  62             if libname not in _gSystem.GetLibraries():
  63                 regex = "^duplicate entry .* for level 0; ignored$"
  64                 with log["/ROOT.TEnvRec.ChangeValue"].ignore(regex):
  65                     if Load(libname) == 0:
  66                         log.debug("Loaded {0} (required by {1})".format(
  67                             libname, symbol))
  68                     else: # pragma: no cover
  69                         raise RuntimeError(
  70                             "Unable to load {0} (required by {1})".format(
  71                                 libname, symbol))
  72 
  73         try:
  74             thing = Quick(symbol)
  75         except NameError:  # pragma: no cover
  76             # NameError: global name 'module' is not defined
  77             # Python must be exiting...
  78             return None
  79         if isinstance(thing, root_module.PropertyProxy):  # descriptor
  80             setattr(self.__class__, symbol, thing)
  81             return getattr(self, symbol)
  82         # normal member
  83         return thing
  84
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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 @@
                       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(
  
verification_info: {"golden_diff": "diff --git a/rootpy/utils/quickroot.py b/rootpy/utils/quickroot.py\n--- a/rootpy/utils/quickroot.py\n+++ b/rootpy/utils/quickroot.py\n@@ -65,6 +65,12 @@\n                     if Load(libname) == 0:\n                         log.debug(\"Loaded {0} (required by {1})\".format(\n                             libname, symbol))\n+                    elif lib == 'Gui':\n+                        # Possibly no X11 forwarding\n+                        log.debug(\"Unable to load {0} (required by {1}). \"\n+                                  \"Putting ROOT in batch mode.\".format(\n+                            libname, symbol))\n+                        ROOT.gROOT.SetBatch(True)\n                     else: # pragma: no cover\n                         raise RuntimeError(\n                             \"Unable to load {0} (required by {1})\".format(\n", "issue": "Exception on import when not forwarding X11\nDear developers,\r\n\r\nI believe I'm experiencing a bug when trying to use rootpy over SSH. Simply importing\r\n```Python\r\nfrom rootpy.plotting import Hist\r\n```\r\nresults in an exception:\r\n```Python\r\nWARNING:ROOT.TUnixSystem.SetDisplay] DISPLAY not set, setting it to :pts/0:S.8\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/__init__.py\", line 12, in <module>\r\n    from .legend import Legend\r\n  File \"/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py\", line 318, in _importhook\r\n    return _orig_ihook( name, *args, **kwds )\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/legend.py\", line 8, in <module>\r\n    from .box import _Positionable\r\n  File \"/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py\", line 318, in _importhook\r\n    return _orig_ihook( name, *args, **kwds )\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/box.py\", line 5, in <module>\r\n    from .utils import canvases_with\r\n  File \"/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py\", line 318, in _importhook\r\n    return _orig_ihook( name, *args, **kwds )\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/utils.py\", line 7, in <module>\r\n    from .canvas import _PadBase\r\n  File \"/gridsoft/ipnls/root/v6.10.04/lib/ROOT.py\", line 318, in _importhook\r\n    return _orig_ihook( name, *args, **kwds )\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/plotting/canvas.py\", line 186, in <module>\r\n    class Pad(_PadBase, QROOT.TPad):\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/utils/module_facade.py\", line 84, in __getattr__\r\n    result = sup.__getattr__(key)\r\n  File \"/home/cms/popov/.local/lib/python3.5/site-packages/rootpy/utils/quickroot.py\", line 71, in __getattr__\r\n    libname, symbol))\r\nRuntimeError: Unable to load libGui (required by TPad)\r\n```\r\nThe problem does not occur if I connect with `ssh -Y`, but I would expect rootpy be usable also without GUI.\r\n\r\nI'm using rootpy 1.0.0 installed with pip, Python 3.5.3, ROOT 6.10.04 with Scientific Linux 6.5.\n", "before_files": [{"content": "\"\"\"\nQuickly load ROOT symbols without triggering PyROOT's finalSetup().\nThe main principle is that appropriate dictionaries first need to be loaded.\n\"\"\"\nfrom __future__ import absolute_import\n\nimport ROOT\n\nfrom .. import log; log = log[__name__]\nfrom .module_facade import Facade\n\n__all__ = []\n\n\nroot_module = ROOT.module._root\nif hasattr(root_module, 'LookupCppEntity'):  # pragma: no cover\n    lookup_func = 'LookupCppEntity'\nelse:  # pragma: no cover\n    lookup_func = 'LookupRootEntity'\n\n# Quick's __name__ needs to be the ROOT module for this to be transparent.\n# The below is one way of obtaining such a function\n# First determine the ROOT version without triggering PyROOT's finalSetup()\nQuick = eval('lambda symbol: module._root.{0}(symbol)'.format(lookup_func),\n             ROOT.__dict__)\n\n_gSystem = Quick(\"gSystem\")\nLoad = _gSystem.Load\n\n# It is not vital to list _all_ symbols in here, just enough that a library\n# will be loaded by the time it is needed.\nSYMBOLS = dict(\n    Hist='TH1 TGraph TGraphAsymmErrors',\n    Tree='TCut TTree',\n    Gui='TPad TCanvas',\n    Graf='TLegend TLine TEllipse',\n    Physics='TVector2 TVector3 TLorentzVector TRotation TLorentzRotation',\n    Matrix='TMatrixT',\n    RooStats='RooStats RooMsgService',\n    RooFit='RooFit RooWorkspace',\n)\n\n# Mapping of symbols to libraries which need to be loaded\nSYMBOLS_TO_LIB = dict(\n    (sym, lib) for lib, syms in SYMBOLS.items() for sym in syms.split())\n\n# If you encounter problems with particular symbols, add them to this set.\nSLOW = set(\"\".split())\n\n\n@Facade(__name__, expose_internal=False)\nclass QuickROOT(object):\n    def __getattr__(self, symbol):\n        if symbol in SLOW:  # pragma: no cover\n            log.warning(\n                \"Tried to quickly load {0} which is always slow\".format(symbol))\n\n        lib = SYMBOLS_TO_LIB.get(symbol, None)\n        if lib:\n            # Load() doesn't cost anything if the library is already loaded\n            libname = \"lib{0}\".format(lib)\n            if libname not in _gSystem.GetLibraries():\n                regex = \"^duplicate entry .* for level 0; ignored$\"\n                with log[\"/ROOT.TEnvRec.ChangeValue\"].ignore(regex):\n                    if Load(libname) == 0:\n                        log.debug(\"Loaded {0} (required by {1})\".format(\n                            libname, symbol))\n                    else: # pragma: no cover\n                        raise RuntimeError(\n                            \"Unable to load {0} (required by {1})\".format(\n                                libname, symbol))\n\n        try:\n            thing = Quick(symbol)\n        except NameError:  # pragma: no cover\n            # NameError: global name 'module' is not defined\n            # Python must be exiting...\n            return None\n        if isinstance(thing, root_module.PropertyProxy):  # descriptor\n            setattr(self.__class__, symbol, thing)\n            return getattr(self, symbol)\n        # normal member\n        return thing\n", "path": "rootpy/utils/quickroot.py"}], "after_files": [{"content": "\"\"\"\nQuickly load ROOT symbols without triggering PyROOT's finalSetup().\nThe main principle is that appropriate dictionaries first need to be loaded.\n\"\"\"\nfrom __future__ import absolute_import\n\nimport ROOT\n\nfrom .. import log; log = log[__name__]\nfrom .module_facade import Facade\n\n__all__ = []\n\n\nroot_module = ROOT.module._root\nif hasattr(root_module, 'LookupCppEntity'):  # pragma: no cover\n    lookup_func = 'LookupCppEntity'\nelse:  # pragma: no cover\n    lookup_func = 'LookupRootEntity'\n\n# Quick's __name__ needs to be the ROOT module for this to be transparent.\n# The below is one way of obtaining such a function\n# First determine the ROOT version without triggering PyROOT's finalSetup()\nQuick = eval('lambda symbol: module._root.{0}(symbol)'.format(lookup_func),\n             ROOT.__dict__)\n\n_gSystem = Quick(\"gSystem\")\nLoad = _gSystem.Load\n\n# It is not vital to list _all_ symbols in here, just enough that a library\n# will be loaded by the time it is needed.\nSYMBOLS = dict(\n    Hist='TH1 TGraph TGraphAsymmErrors',\n    Tree='TCut TTree',\n    Gui='TPad TCanvas',\n    Graf='TLegend TLine TEllipse',\n    Physics='TVector2 TVector3 TLorentzVector TRotation TLorentzRotation',\n    Matrix='TMatrixT',\n    RooStats='RooStats RooMsgService',\n    RooFit='RooFit RooWorkspace',\n)\n\n# Mapping of symbols to libraries which need to be loaded\nSYMBOLS_TO_LIB = dict(\n    (sym, lib) for lib, syms in SYMBOLS.items() for sym in syms.split())\n\n# If you encounter problems with particular symbols, add them to this set.\nSLOW = set(\"\".split())\n\n\n@Facade(__name__, expose_internal=False)\nclass QuickROOT(object):\n    def __getattr__(self, symbol):\n        if symbol in SLOW:  # pragma: no cover\n            log.warning(\n                \"Tried to quickly load {0} which is always slow\".format(symbol))\n\n        lib = SYMBOLS_TO_LIB.get(symbol, None)\n        if lib:\n            # Load() doesn't cost anything if the library is already loaded\n            libname = \"lib{0}\".format(lib)\n            if libname not in _gSystem.GetLibraries():\n                regex = \"^duplicate entry .* for level 0; ignored$\"\n                with log[\"/ROOT.TEnvRec.ChangeValue\"].ignore(regex):\n                    if Load(libname) == 0:\n                        log.debug(\"Loaded {0} (required by {1})\".format(\n                            libname, symbol))\n                    elif lib == 'Gui':\n                        # Possibly no X11 forwarding\n                        log.debug(\"Unable to load {0} (required by {1}). \"\n                                  \"Putting ROOT in batch mode.\".format(\n                            libname, symbol))\n                        ROOT.gROOT.SetBatch(True)\n                    else: # pragma: no cover\n                        raise RuntimeError(\n                            \"Unable to load {0} (required by {1})\".format(\n                                libname, symbol))\n\n        try:\n            thing = Quick(symbol)\n        except NameError:  # pragma: no cover\n            # NameError: global name 'module' is not defined\n            # Python must be exiting...\n            return None\n        if isinstance(thing, root_module.PropertyProxy):  # descriptor\n            setattr(self.__class__, symbol, thing)\n            return getattr(self, symbol)\n        # normal member\n        return thing\n", "path": "rootpy/utils/quickroot.py"}]}