AttributeError:"DiGraph"对象没有属性"_node" [英] AttributeError: 'DiGraph' object has no attribute '_node'

查看:2349
本文介绍了AttributeError:"DiGraph"对象没有属性"_node"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该代码是由其他人使用Python 2.7.12,networkx 1.11,numpy 1.13.0,scipy 0.18.1,matplotlib 2.0.2编写的.它由几个自制模块组成.我已经使用"2to3"转换器将整个代码转换为Python3.x.我正在使用具有所有最新软件包的Spyder运行整个代码.

The code is written by someone else using Python 2.7.12, networkx 1.11, numpy 1.13.0, scipy 0.18.1, matplotlib 2.0.2. It consists of several self-made modules. I have converted the entire code to Python 3.x using "2to3" converter. I am running the entire code using Spyder which has all the latest packages.

现在,在运行代码时,出现AttributeError: 'DiGraph' object has no attribute '_node'错误.以下是spyder中的错误消息.

Now while running the code I am getting AttributeError: 'DiGraph' object has no attribute '_node' error. Following is the error message in 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'

如果解决方案需要,我可以提供部分代码.

I can provide the part of the code if required for a solution.

注意:代码与旧软件包一起成功运行.

Note: the code is running successfully with the old packages.

推荐答案

如果运行在旧版本中,但不是现在运行,则此错误可能是由于旧代码与networkx 2.x不兼容引起的.您应阅读迁移指南以进行更新1. x代码可在networkx 2.0中运行.

If it runs in the old version, but not now, this error is probably caused by the old code being incompatible with networkx 2.x. You should read the migration guide for updating 1.x code to run in networkx 2.0.

编辑:从注释中可以看出,问题很明显,该图是在1.x中创建的,然后对其进行了腌制.因此它具有1.x属性.但是现在,它与需要2.x属性的2.x代码一起使用. 此处.

edit: from comments, it's now clear that the problem was that the graph was created in 1.x and then pickled. So it has the 1.x attributes. But now it's being used with 2.x code which expects 2.x attributes. The solution is explained here.

这篇关于AttributeError:"DiGraph"对象没有属性"_node"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆