Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
[ROOT-8459] Incorrect import statements in JupyROOT module Created: 17/Nov/16 Updated: 15/Dec/16 Resolved: 15/Dec/16 Status: Project: Component/s: Affects Version/s: Fix Version/s: Closed ROOT PyROOT 6.08/00 Type: Reporter: Resolution: Environment: Bug Priority: Konstantin Gizdov Assignee: Fixed Votes: GCC 6.2.1, Linux x64 4.8.8, Python3 Attachments: JupyROOT_fix.patch x86_64-slc6-gcc48-opt Platforms: None High Danilo Piparo 0 Description If http is switched on and JupyROOT is enabled, then python fails to load the module as its components do not specify hierarchy correctly. When trying to import ROOT (or any of its modules) into a Jupyter notebook, the import fails. The resulting errors are ''ImportError: No module named handlers' or the same for 'cppcompleter' and 'utils'. I've attached a patch to correct this behaviour. Comments Comment by Konstantin Gizdov [ 17/Nov/16 ] Should I make a pull request on GitHub for this, btw? Comment by Danilo Piparo [ 17/Nov/16 ] Hi Kostantin, thanks for the report and proposed solution: I am looking into it. Cheers, D Comment by Danilo Piparo [ 17/Nov/16 ] Hi Kostantin, I tried your patch but it breaks builds relying on Python2. [....] 6 #---------------------------------------------------------------------------7 ----> 8 from JupyROOT import utils 9 import ROOT 10 ImportError: cannot import name utils Can you confirm you are working with Python3? Cheers, D Comment by Konstantin Gizdov [ 17/Nov/16 ] Hi, I can confirm I am using Python3, however the error you indicated is a symptom of something linked to by the module failing, not that it could not be loaded/found. When I try to run it with python2 the main error is that ROOT hasn't defined bindings for python2, there are no errors regarding import statemens. In [1]: import JupyROOT -------------------------------------------------------------------------ImportError Traceback (most recent call last) <ipython-input-1-c66cbb66c445> in <module>() ----> 1 import JupyROOT /usr/lib/root/JupyROOT/__init__.py in <module>() ----> 1 import JupyROOT.utils 2 3 if '__IPYTHON__' in __builtins__ and __IPYTHON__: 4 utils.iPythonize() /usr/lib/root/JupyROOT/utils.py in <module>() 24 from IPython.core.extensions import ExtensionManager 25 import IPython.display ---> 26 import ROOT 27 from JupyROOT import cppcompleter 28 /usr/lib/root/ROOT.py in <module>() 22 ### system and interpreter setup ----------------------------------------------23 import os, sys, types ---> 24 import cppyy 25 26 ## there's no version_info in 1.5.2 /usr/lib/root/cppyy.py in <module>() 58 sys.setdlopenflags( 0x100 | 0x2 ) RTLD_GLOBAL | RTLD_NOW 59 ---> 60 import libPyROOT as _backend 61 62 # reset dl flags if needed # ImportError: dynamic module does not define init function (initlibPyROOT) However, the error I get is to be expected as I build against python 3. If I have built against python2 that init function will not be missing I believe and it should succeed. Comment by Danilo Piparo [ 17/Nov/16 ] Hi Konstantin, thanks for the confirmation. What I am trying to say is that your fix does not work when root is built against Python2. Cheers, D Comment by Konstantin Gizdov [ 28/Nov/16 ] Hi, I tried a few other fixes, but I don't think there is a safe way of including the package that is valid for python2 and python3 simultaneously. What do you propose to do? Comment by Danilo Piparo [ 12/Dec/16 ] Hi Kostantin, can we maybe check the python version and selectively execute statements? E.g.: import sys if sys.hexversion >= 0x3000000: print('Python 3.x hexversion %s is in use.' % hex(sys.hexversion)) Comment by Danilo Piparo [ 15/Dec/16 ] Hi, this was due to circular dependencies in the way we defined the JupyROOT helper modules. This has been fixed in the master. Thanks Generated at Sat Apr 29 22:25:26 CEST 2017 using JIRA 7.2.7#72009sha1:68b7d86b7e8716f76c1f28a5095acccf67bb75b1.