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

查看:35
本文介绍了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.

  1. 已下载networkx-1.11.zip
  2. 解压压缩文件
  3. 打开cmd和cd到解压目录
  4. 运行 python setup.py install
  5. 使用 pip freeze
  6. 验证安装
  7. 将测试代码保存在 netExample.py 文件中.
  8. 在 CMD 中,cd 到包含 netExample.py
  9. 的文件夹
  10. 运行 python netExample.py

以下是我得到的输出:

D:Naveenso>python netExample.py
[]
[]
<class 'list'>
<class 'list'>

请检查以下内容:

  1. 验证您是否从官方网站下载.
  2. 中存在实际的 networkx 模块之前,检查 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天全站免登陆