首页 文章

'module'对象没有属性'Dot'

提问于
浏览
-2

我是python的初学者,我正在尝试使用以下方法绘制图形:

`nx.write_dot(G, "%s.dot"%(image))`

在一个定义的函数中 . 当我执行该程序时,我收到此错误:

在main()中的第31行文件“sim.py”

在主sol.run()中输入“sim.py”,第30行

文件“C:\ Python27 \ My sim \ Solution.py”,第221行,运行self.drawGraph(G,“solution1”)

文件“C:\ Python27 \ My sim \ Solution.py”,第227行,在drawGraph中nx.write_dot(G,“%s.dot”%(image))

在write_dot中的文件“”,第2行

文件“C:\ Python27 \ lib \ site-packages \ networkx \ utils \ decorators.py”,第220行,在_open_file中

result = func(* new_args,** kwargs)

在write_dot中的文件“C:\ Python27 \ lib \ site-packages \ networkx \ drawing \ nx_pydot.py”,第58行

P = to_pydot(G)

文件“C:\ Python27 \ lib \ site-packages \ networkx \ drawing \ nx_pydot.py”,第197行,在to_pydot中

P = pydot.Dot(graph_type = graph_type,strict = strict,** graph_defaults)AttributeError:'module'对象没有属性'Dot'

It seems it is a Windows os problem (I'm on win7), because my colleague can run the same script on his ubuntu machine without any error.

谢谢你的帮助!

1 回答

  • 0

    你正在做教程 Drawing graphs 对吗?

    这里是如何工作的:

    import networkx as nx
    import matplotlib.pyplot as plt
    
    G=nx.Graph()
    G.add_edges_from([(1,2),(1,3)])
    nx.draw(G)
    plt.show()
    

    Edit: 如果你没有安装matplotlib,只需打开命令行并输入:

    pip install matplotlib
    

    matplotlib是可选的,它不带有networkx,你必须安装它 .

    另外要保存 .dot 文件,只需添加以下行:

    nx.write_dot(G,'C:/file.dot')
    

    没有 matplotlibEdit: 将是这样的:

    import networkx as nx
    
    G=nx.Graph()
    G.add_edges_from([(1,2),(1,3)])
    nx.draw(G)
    nx.write_dot(G,'C:/file.dot')
    

    我注意到你的代码 nx.write_dot(G, "%s.dot"%(image)) 你没有定义 image 和G,错误应该来自其中一个 .

    但如果你想安装c编译器,我建议下载Visual C++ Compiler 33mb或Microsoft visual studio community,它们是免费的 .

相关问题