目录

一、解决如下:

二、错误分析:


在使用


TextRank4Keyword().analyze(text, lower=True, window=2)


的时候报错:

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

可以选择降级networkx 到3.0以下或改用 nx.from_numpy_array

一、我的解决如下:

1、进入源码\Python\Python310\Lib\site-packages\textrank4zh\util.py

2、定位到160行

nx_graph = nx.from_numpy_matrix(graph)

3、修改这一行代码

nx_graph = nx.from_numpy_array(graph)

AttributeError: module ‘networkx‘ has no attribute ‘from_numpy_matrix‘_开发语言

4、再运行程序就可以了

二、错误分析:

1、我使用的是networkx 3.1

2、networkx 3.0开始就删除了from_numpy_matrix()

详见官方文档:NetworkX 3.0 — NetworkX 3.1 documentation

AttributeError: module ‘networkx‘ has no attribute ‘from_numpy_matrix‘_错误分析_02

 3、from_numpy_array()的使用from_numpy_array — NetworkX 3.1 documentation

AttributeError: module ‘networkx‘ has no attribute ‘from_numpy_matrix‘_错误分析_03