本文介绍了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:pythonpython36-32libsite-packagesdecorator-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'
运行 print(dr(nx))
给出以下属性:
Running print(dr(nx))
gives the following attributes:
> ['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.
- 已下载networkx-1.11.zip
- 解压压缩文件
- 打开cmd和
cd到解压目录
- 运行
python setup.py install
- 使用
pip freeze
验证安装 - 将测试代码保存在
netExample.py
文件中. - 在 CMD 中,cd 到包含
netExample.py
的文件夹 - 运行
python netExample.py
以下是我得到的输出:
D:Naveenso>python netExample.py
[]
[]
<class 'list'>
<class 'list'>
请检查以下内容:
- 验证您是否从官方网站下载.
- 在 中存在实际的
networkx
模块之前,检查 Windows 路径中是否存在任何其他名为 networkx.py
的文件- Verify whether you are downloading from the official website.
- Check if any other file named
networkx.py
is present in Windows Path before the actualnetworkx
module is present in
这篇关于AttributeError: 模块“networkx"没有属性“Graph"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!