导入包的方式有点奇怪,用的不是包名“python-louvain”而是“community”,
import community as community_louvain
在jupyter中运行“partition = community_louvain.best_partition(G) #进行图划分”的时候出现以下错误:
AttributeError: module ‘community’ has no attribute 'best_partition' 。
第一反应猜测是没安装community包,于是就熟悉的操作 pip install community安排上了。
但是使用中,发现又会报错:
AttributeError: module ‘community’ has no attribute 'best_partition’。
解决办法:
起初以为是community 包的版本问题,后来发现是需要安装python-luovain (用于社区检测的louvain算法 )
解决步骤如下:
(安装python-louvain前要先卸载community)
- pip uninstall community
- pip install python-louvain