簡體   English   中英

AttributeError: 模塊“networkx”沒有屬性“Graph”

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

我通過下載分發文件並運行來安裝 networkx:

python setup.py install

看來已經成功了,我安裝后收到此消息

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

但是當我運行一個非常簡單的測試代碼時,我得到了錯誤

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))給出以下屬性:

> ['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版本中對我python 3.5

  1. 下載networkx-1.11.zip
  2. 解壓壓縮文件
  3. 打開cmd和cd to extracted directory
  4. 運行python setup.py install
  5. 使用pip freeze驗證安裝
  6. 將測試代碼保存在netExample.py文件中。
  7. 在 CMD 中,cd 到包含netExample.py的文件夾
  8. 運行python netExample.py

以下是我得到的輸出:

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

請檢查以下內容:

  1. 驗證您是否從官方網站下載。
  2. 在實際networkx模塊出現之前,檢查 Windows 路徑中是否存在任何其他名為networkx.py文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM