1

似乎连根拔起不承认“开放”。我正在使用文档中的代码;

import uproot 

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

返回 AttributeError: 'module' 对象没有属性 'open'

我正在使用 Python 2.7 和 uproot 3.10.11,但我还安装了一个虚拟环境并尝试了其他 python 和 uproot 版本。我尝试重新安装uproot,并尝试打开其他文件,都返回相同的错误。

有任何想法吗?

4

1 回答 1

1

这听起来更像是一个错误报告(GitHub 问题)而不是一个使用问题(StackOverflow),但即使作为一个错误报告,我也看不出从描述中可能出了什么问题。在安装过程中似乎出现了一些奇怪的错误,以至于您得到了一个名为“uproot”的模块,没有任何内容。“open”函数是导入到“uproot”模块中的第一个函数(它在“uproot.rootio”中定义并在之后导入到主“uproot”命名空间from__future__ import absolute_import;即最早的可能)。

您可以尝试打印dir(uproot)以查看其中的内容,尽管我怀疑其中不会有任何内容。我不知道您是如何最终得到一个名为 uproot 的模块而没有(全部?)其内容的。您说您尝试了不同的安装方法,但不知何故,它们都在重现相同的安装故障。就我而言,我无法重现它——我无法让它发生(包括 Python 2.7,这些天来很少受到关注)。

在没有安装 uproot 的新 Docker 映像上,我做了一个pip install uproot

>>> 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']

您是否能够安装其他 Python 包,还是只是将其连根拔起?

于 2020-03-27T12:18:05.783 回答