简体   繁体   English

AttributeError: 模块“networkx”没有属性“Graph”

[英]AttributeError: module 'networkx' has no attribute 'Graph'

I installed networkx by downloading the distribution file and running:我通过下载分发文件并运行来安装 networkx:

python setup.py install

It appears to have been successful, I got this message after installing看来已经成功了,我安装后收到此消息

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

But when I run a really simple test code, I get errors但是当我运行一个非常简单的测试代码时,我得到了错误

import networkx as nx

G=nx.Graph()

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

print(type(G.nodes()))
print(type(G.edges()))
> Traceback (most recent call last):   File "netExample.py", line 3, in
> <module>
>     G=nx.Graph() 

> AttributeError: module 'networkx' has no attribute 'Graph'

Running print(dr(nx)) gives the following attributes:运行print(dr(nx))给出以下属性:

> ['GraphMLReader', 'GraphMLWriter', '__builtins__', '__cached__',
> '__doc__', '__file__', '__loader__', '__name__', '__package__',
> '__path__', '__spec__', 'exception', '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']

Following the below steps, it worked for me in python 3.5 version.按照以下步骤操作,它在python 3.5版本中对我python 3.5

  1. Downloaded networkx-1.11.zip下载networkx-1.11.zip
  2. Extracted the zip file解压压缩文件
  3. open the cmd and cd to extracted directory打开cmd和cd to extracted directory
  4. run python setup.py install运行python setup.py install
  5. verified the installation using pip freeze使用pip freeze验证安装
  6. saved the test code in netExample.py file.将测试代码保存在netExample.py文件中。
  7. In CMD, cd to the folder, which contains netExample.py在 CMD 中,cd 到包含netExample.py的文件夹
  8. run python netExample.py运行python netExample.py

Following is output that I got:以下是我得到的输出:

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

Please check the following:请检查以下内容:

  1. Verify whether you are downloading from the official website.验证您是否从官方网站下载。
  2. Check if any other file named networkx.py is present in Windows Path before the actual networkx module is present in在实际networkx模块出现之前,检查 Windows 路径中是否存在任何其他名为networkx.py文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:模块“ networkx”没有属性“ complete_graph” - AttributeError: module 'networkx' has no attribute 'complete_graph' AttributeError:模块“networkx”没有属性“utils” - AttributeError: module 'networkx' has no attribute 'utils' AttributeError:&#39;module&#39;对象没有networkx 1.11属性&#39;graphviz_layout&#39; - AttributeError: 'module' object has no attribute 'graphviz_layout' with networkx 1.11 AttributeError:&#39;module&#39;对象没有networkx库的属性&#39;write_dot&#39; - AttributeError: 'module' object has no attribute 'write_dot' for networkx library AttributeError:模块“networkx”没有属性“connected_component_subgraphs” - AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' AttributeError:模块“matplotlib.cbook”在 Networkx 中没有属性“is_numlike” - AttributeError: module 'matplotlib.cbook' has no attribute 'is_numlike' in Networkx AttributeError: &#39;module&#39; 对象没有属性 &#39;Graph&#39; - AttributeError: 'module' object has no attribute 'Graph' &#39;Graph&#39;对象在networkx模块python中没有属性&#39;nodes_iter&#39; - 'Graph' object has no attribute 'nodes_iter' in networkx module python 在 NetworkX 中打开 json 图会产生“模块‘networkx’没有属性‘json_graph’” - Open json graph in NetworkX yields “module 'networkx' has no attribute 'json_graph' ” AttributeError:模块没有属性 - AttributeError: module has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM