AttributeError:模块'networkx'没有属性'Graph'

时间:2017-02-07 08:27:42

标签: python graph networkx

我通过下载分发文件并运行:

来安装networkx
python setup.py install

它似乎已成功,我在安装

后收到此消息
Installed c:\python\python36-32\lib\site-packages\decorator-4.0.11-py3.6.egg
Finished processing dependencies for networkx==1.11

但是当我运行一个非常简单的测试代码时,我会收到错误

import networkx as nx

G=nx.Graph()

print(G.nodes())
print(G.edges())

print(type(G.nodes()))
print(type(G.edges()))
  

回溯(最近一次调用最后一次):文件“netExample.py”,第3行,in          G = nx.Graph()

     

AttributeError:模块'networkx'没有属性'Graph'

运行print(dr(nx))提供以下属性:

  

['GraphMLReader','GraphMLWriter',' builtins ','缓存',   ' doc ','文件','加载程序','名称','包< /强>”,   '路径','规范','例外','generate_adjlist',   'generate_edgelist','generate_gexf','generate_gml',   'generate_graph6','generate_graphml','generate_multiline_adjlist',   'generate_pajek','generate_sparse6','parse_adjlist',   'parse_edgelist','parse_gml','parse_graph6','parse_graphml',   'parse_leda','parse_multiline_adjlist','parse_pajek',   'parse_sparse6','read_adjlist','read_edgelist','read_gexf',   'read_gml','read_gpickle','read_graph6','read_graphml',   'read_leda','read_multiline_adjlist','read_pajek','read_shp',   'read_sparse6','read_weighted_edgelist','read_yaml','readwrite',   'relabel_gexf_graph','utils','write_adjlist','write_edgelist',   'write_gexf','write_gml','write_gpickle','write_graph6',   'write_graphml','write_multiline_adjlist','write_pajek',   'write_shp','write_sparse6','write_weighted_edgelist','write_yaml']

1 个答案:

答案 0 :(得分:1)

按照以下步骤,它适用于python 3.5版本。

  1. 已下载networkx-1.11.zip
  2. 提取zip文件
  3. 打开cmd和cd to extracted directory
  4. 运行python setup.py install
  5. 使用pip freeze
  6. 验证了安装
  7. 将测试代码保存在netExample.py文件中。
  8. 在CMD中,cd到包含netExample.py
  9. 的文件夹
  10. 运行python netExample.py
  11. 以下是我得到的输出:

    D:\Naveen\so>python netExample.py
    []
    []
    <class 'list'>
    <class 'list'>
    

    请检查以下内容:

    1. 验证您是否从官方网站下载。
    2. 中存在实际的networkx.py模块之前,检查Windows路径中是否存在任何其他名为networkx的文件