Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-10159

from ROOT import <something> on python cmd line fails if IPython is already imported

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: master
    • Fix Version/s: 6.22/00
    • Component/s: PyROOT
    • Labels:
      None
    • Environment:

      ROOT master
      python 3.7.3
      pyroot_experimental

      Description

      Hello,

      I'm just trying pyroot_experimental (master, py3). This is OK (using python command line and not ipython):

      $ python
      Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
      [GCC 7.3.0] :: Anaconda, Inc. on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import ROOT
      >>> ROOT.gSystem
      <cppyy.gbl.TSystem* object at 0x556382af29f0>
      >>>
      

      However, there is an error if IPython is already imported (if it is already in sys.modules):

      $ python
      Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
      [GCC 7.3.0] :: Anaconda, Inc. on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import IPython
      >>> import ROOT
      >>> ROOT
      <module 'ROOT' from '/home/builder/work/opt/root-master/lib/ROOT/__init__.py'>
      >>> ROOT.gSystem
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/builder/work/opt/root-master/lib/ROOT/_facade.py", line 58, in _getattr
      self._finalSetup()
      File "/home/builder/work/opt/root-master/lib/ROOT/_facade.py", line 51, in _finalSetup
      self.app.init_graphics()
      File "/home/builder/work/opt/root-master/lib/ROOT/_application.py", line 76, in init_graphics
      self._ipython_config()
      File "/home/builder/work/opt/root-master/lib/ROOT/_application.py", line 43, in _ipython_config
      ipy = get_ipython()
      NameError: name 'get_ipython' is not defined
      

      I guess that there is a problem in PyROOTApplication.init_graphics (https://github.com/root-project/root/blob/master/bindings/pyroot_experimental/PyROOT/python/ROOT/_application.py). I don't know when __IPYTHON__ gets into __builtins__ (when running ipython interactively?) and if it implies that 'IPython' is in sys.modules or not.

      Maybe instead of:

      is_ipython = hasattr(__builtins__, '__IPYTHON__') or 'IPython' in sys.modules
      

      there should be probably only (not tested):

      is_ipython = hasattr(__builtins__, '__IPYTHON__')
      

      ?

      Cheers,
      Jiri

        Attachments

          Activity

            People

            • Assignee:
              etejedor Enric Tejedor Saavedra
              Reporter:
              jprochaz Jiri Prochazka
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: