Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't import rootpy in Python 3.8 #812

Open
masonproffitt opened this issue Dec 8, 2019 · 5 comments
Open

Can't import rootpy in Python 3.8 #812

masonproffitt opened this issue Dec 8, 2019 · 5 comments

Comments

@masonproffitt
Copy link

If you try to use rootpy in Python 3.8, this is what happens:

>>> import rootpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/site-packages/rootpy/__init__.py", line 29, in <module>
    from .logger import log
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/site-packages/ROOT.py", line 533, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/site-packages/rootpy/logger/__init__.py", line 111, in <module>
    handler.setFormatter(CustomColoredFormatter())
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/site-packages/rootpy/logger/formatter.py", line 51, in __init__
    CustomFormatter.__init__(self, fmt, datefmt)
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/site-packages/rootpy/logger/formatter.py", line 40, in __init__
    logging.Formatter.__init__(self, fmt, datefmt)
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/logging/__init__.py", line 576, in __init__
    self._style.validate()
  File "/gscratch/stf/masonlp/conda/envs/root/lib/python3.8/logging/__init__.py", line 429, in validate
    raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
ValueError: Invalid format '{color}{levelname}:{name}] {message}' for '%' style

This is because CustomFormatter calls logging.Formatter.__init__() with a .format() style string, but the style for Formatter defaults to '%' (see https://docs.python.org/3/library/logging.html#logging.Formatter). format() is overridden for the class, which is why everything works in Python versions before 3.8, but 3.8 added a validate=True parameter, which verifies that the given string actually follows the expected format. Otherwise it raises an error like above.

@masonproffitt masonproffitt changed the title Can't import rootpy in Python 3.8 Can't import rootpy in Python 3.8 Dec 8, 2019
masonproffitt added a commit to masonproffitt/rootpy that referenced this issue Dec 8, 2019
@xaratustrah
Copy link

xaratustrah commented May 11, 2020

I also get the same error while importing into python3.8. I am using the latest rootproject/root-archlinux docker image.

I tried to use @masonproffitt fix, directly from their fork as they described above. The issue with import rootpy was solved, but when importing other stuff, such as from rootpy.plotting import Hist, I get the following errors:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/rootpy/rootpy/plotting/__init__.py", line 6, in <module>
    from ..utils.hook import classhook, super_overridden
  File "/usr/lib/python3.8/site-packages/ROOT.py", line 522, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/tmp/rootpy/rootpy/utils/hook.py", line 6, in <module>
    from .inject_closure import inject_closure_values
  File "/usr/lib/python3.8/site-packages/ROOT.py", line 522, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/tmp/rootpy/rootpy/utils/inject_closure.py", line 5, in <module>
    from ..extern import byteplay3 as byteplay
  File "/usr/lib/python3.8/site-packages/ROOT.py", line 522, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/tmp/rootpy/rootpy/extern/byteplay3/__init__.py", line 9, in <module>
    from .wbyteplay import *
  File "/usr/lib/python3.8/site-packages/ROOT.py", line 522, in _importhook
    return _orig_ihook( name, *args, **kwds )
  File "/tmp/rootpy/rootpy/extern/byteplay3/wbyteplay.py", line 93, in <module>
    BREAK_LOOP,
NameError: name 'BREAK_LOOP' is not defined

@sahilyadav27
Copy link

I also faced a similar issue while converting a ROOT file into a hdf5 file using root2hdf5. Were you able to find any solution to this error?

@xaratustrah
Copy link

@sahilyadav27 No I didn't succeed. Seems to be a more detailed problem. For your application maybe you can check uproot, to read ROOT files and convert them to hdf5 format yourself using h5py.

@sahilyadav27
Copy link

Thanks for the information @xaratustrah ! I was able to solve this issue by downgrading python to 3.7 since rootpy doesn't work well with 3.8. But there were some other issues while reading tree branches though.

@benedettosiddi
Copy link

It does not work also in python 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants