1

It seems uproot doesn't recognise "open". I'm using code from the documentation;

import uproot 

file = uproot.open("http://scikit-hep.org/uproot/examples/nesteddirs.root")

which returns AttributeError: 'module' object has no attribute 'open'

I'm using Python 2.7 and uproot 3.10.11, but I've also installed a virtual environment and tried other python and uproot versions. I've tried to reinstall uproot and I've tried to open other files, all returns the same error.

Any ideas?

liv
  • 11
  • 2

1 Answers1

1

This sounds more like a bug report (GitHub Issues) than a usage question (StackOverflow), but even as a bug report, I don't see what could be going wrong from the description. It seems like something went bizarrely wrong during the installation, such that you get a module named "uproot" without any of its contents. The "open" function is the very first thing that gets imported into the "uproot" module (it's defined in "uproot.rootio" and imported into the main "uproot" namespace right after from__future__ import absolute_import; i.e. the earliest it possibly can be).

You could try printing dir(uproot) to see what's in it, though I suspect there will be nothing in it. I don't know how you ended up with a module named uproot without (all of?) its contents. You say you've tried different installation methods, but somehow they're all reproducing the same installation glitch. On my side, I can't reproduce itβ€”I can't make it happen (including Python 2.7, which gets less attention these days).

On a new Docker image with no uproot installed, I did a pip install uproot and

>>> import uproot
>>> dir(uproot)
['ArrayCache', 'FileSource', 'HTTPSource', 'LZ4', 'LZMA', 'MemmapSource',
 'Pointer', 'STLMap', 'STLString', 'STLVector', 'SimpleArray',
 'ThreadSafeArrayCache', 'XRootDSource', 'ZLIB', '__all__',
 '__builtins__', '__doc__', '__file__', '__name__', '__package__',
 '__path__', '__version__', '_connect', '_help', 'absolute_import',
 'asarray', 'asdebug', 'asdouble32', 'asdtype', 'asgenobj', 'asjagged',
 'asobj', 'asstlbitset', 'asstring', 'astable', 'cache', 'const',
 'create', 'daskarray', 'daskframe', 'http', 'interp', 'interpret',
 'iterate', 'lazyarray', 'lazyarrays', 'newbranch', 'newtree',
 'numentries', 'open', 'pandas', 'recreate', 'rootio', 'source', 'tree',
 'update', 'version', 'write', 'xrootd']

Are you able to install other Python packages or is it just uproot?

Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47
  • Thanks for the reply. Printing dir(uproot) returns ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'uproot'] ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'np', 'uproot'] I'm able to install other Python packages that seem to work fine. – liv Mar 27 '20 at 15:29
  • Normally, the `uproot` module would be filled with a lot of functions. This looks like the keys of `globals()`. You're not doing `from uproot import *`, are you? – Jim Pivarski Mar 27 '20 at 18:02
  • No, I was doing `import root`. I finally fixed the issue by reinstalling python. Thanks for the help! – liv Apr 01 '20 at 06:53