AttributeError:模块"networkx"没有属性"Graph" [英] AttributeError: module 'networkx' has no attribute 'Graph'

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

问题描述

我通过下载分发文件并运行来安装networkx:

I installed networkx by downloading the distribution file and running:

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()))

回溯(最近一次通话最后一次):文件"netExample.py",第3行,在 G = nx.Graph()

Traceback (most recent call last): File "netExample.py", line 3, in G=nx.Graph()

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

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

正在运行的print(dr(nx))具有以下属性:

Running print(dr(nx)) gives the following attributes:

['GraphMLReader','GraphMLWriter','内置插件','已缓存', ' 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']

['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']

推荐答案

按照以下步骤,它在python 3.5版本中对我有用.

Following the below steps, it worked for me in python 3.5 version.

  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
  1. Downloaded networkx-1.11.zip
  2. Extracted the zip file
  3. open the cmd and cd to extracted directory
  4. run python setup.py install
  5. verified the installation using pip freeze
  6. saved the test code in netExample.py file.
  7. In CMD, cd to the folder, which contains netExample.py
  8. run python netExample.py

以下是我得到的输出:

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

请检查以下内容:

  1. 验证是否要从官方网站下载.
  2. 在实际的networkx模块出现在
  3. 中之前,检查Windows路径中是否存在任何其他名为networkx.py的文件.
  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

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

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