代码由其他人使用Python 2.7.12,networkx 1.11,numpy 1.13.0,scipy 0.18.1,matplotlib 2.0.2编写。它由几个自制模块组成。我已经使用“2to3”转换器将整个代码转换为Python 3.x.我正在使用包含所有最新软件包的Spyder运行整个代码。
现在,在运行代码时,我收到AttributeError: 'DiGraph' object has no attribute '_node'
错误。以下是spyder中的错误消息。
runfile('C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py', wdir='C:/Users/NaVnEeT/Desktop/Thesis/WIP2')
__main__ : INFO main() started
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
Settings : INFO Settings __init__ finished
TransGrph : INFO Graph is loaded from file
Traceback (most recent call last):
File "<ipython-input-1-c61da2f96623>", line 1, in <module>
runfile('C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py', wdir='C:/Users/NaVnEeT/Desktop/Thesis/WIP2')
File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py", line 137, in <module>
main()
File "C:/Users/NaVnEeT/Desktop/Thesis/WIP2/main.py", line 92, in main
ch8NLR()
File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\thesis\ch8NLR.py", line 176, in ch8NLR
graph = TransportGraph(settings[0])
File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\buildgraph\transportgraph.py", line 58, in __init__
self.dmatrix = add_dmatrix(self.G, settings)
File "C:\Users\NaVnEeT\Desktop\Thesis\WIP2\code\buildgraph\demandmatrix.py", line 20, in add_dmatrix
origdest_graph = [x for x in G.nodes() if x[0] == 'F']
File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\networkx\classes\graph.py", line 717, in nodes
nodes = NodeView(self)
File "C:\Users\NaVnEeT\Anaconda3\lib\site-packages\networkx\classes\reportviews.py", line 168, in __init__
self._nodes = graph._node
AttributeError: 'DiGraph' object has no attribute '_node'
如果解决方案需要,我可以提供部分代码。
注意:代码与旧包一起成功运行。
答案 0 :(得分:1)
如果它在旧版本中运行,但现在不运行,则此错误可能是由旧代码与networkx 2.x不兼容引起的。您应该阅读migration guide以更新1.x代码以在networkx 2.0中运行。
编辑:来自评论,现在很明显问题是图表是在1.x中创建然后进行了腌制。所以它有1.x属性。但现在它与2.x代码一起使用,它需要2.x属性。解决方案解释为here。