我对根根有个问题。当我试图导入根直方图时,我总是得到相同的AttributeError。
>>> from ROOT import TH1F
AttributeError: type object 'TArray' has no attribute '__getitem__'
During handling of the above exception, another exception occurred:
SystemError: <built-in method mro of ROOT.PyRootType object at 0x328fb18> returned a result with an error set
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TH1F'我也尝试过rootpy,但它不起作用。可能是亲戚?
我安装了Python3.5,并使用gcc 5.2.0完成了根用户的干净安装。我在运行root-config --features时列出了Python模块。
有什么想法吗?或者解决方案?
发布于 2015-10-27 08:41:32
您所面临的问题与Python中最近的更改有关,它解决了错误的异常处理。Pythonize.cxx包装器中的调用试图将__getitem__属性重命名为不存在的类TArray。这导致了在python3.5发行版之前被忽略的AttributeError。
要恢复旧行为,需要修改$ROOTSYS/bindings/pyroot/src/目录中的文件$ROOTSYS/bindings/pyroot/src/。搜索方法
Bool_t PyROOT::Utility::AddToClass( PyObject* pyclass, const char* label, const char* func )应该在230线左右。在此方法中有一个if条件:
if ( ! pyfunc )
return kFALSE;在这里,您需要用以下行替换上面的代码:
if ( ! pyfunc ) {
PyErr_Clear();
return kFALSE;
}PyErr_Clear()的调用将解决这个问题。保存文件并重新编译根安装。这应该能解决问题。
编辑:这个问题已经有了一个错误报告:https://sft.its.cern.ch/jira/browse/ROOT-7640
https://stackoverflow.com/questions/33361998
复制相似问题