AttributeError:模块"networkx"没有属性"Graph" [英] AttributeError: module 'networkx' has no attribute '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.
- 下载了 networkx-1.11.zip
- 提取了zip文件
- 打开cmd,然后
cd to extracted directory
- 运行
python setup.py install
- 使用
pip freeze
验证了安装
- 将测试代码保存在
netExample.py
文件中. - 在CMD中,将cd转到包含
netExample.py
的文件夹
- 运行
python netExample.py
- Downloaded networkx-1.11.zip
- Extracted the zip file
- open the cmd and
cd to extracted directory
- run
python setup.py install
- verified the installation using
pip freeze
- saved the test code in
netExample.py
file. - In CMD, cd to the folder, which contains
netExample.py
- run
python netExample.py
以下是我得到的输出:
D:\Naveen\so>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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!