复杂网络中louvain算法实现时报错AttributeError: module ‘community‘ has no attribute ‘best_partition‘

在使用Louvain算法时遇到AttributeError,提示模块'community'没有属性'best_partition'。尝试通过pip安装'community'包未解决问题。解决方法是卸载'community',安装'python-louvain'包,或者直接下载python-louvain的zip文件到Python库中安装。完成安装后,问题得到解决。
摘要由CSDN通过智能技术生成

导入包的方式有点奇怪,用的不是包名“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)

  1. pip uninstall community
  2. pip install python-louvain

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值