如何使用networkx 2.2中的社区模块? [英] How to use the communities module "python-louvain" in networkx 2.2?

查看:22
本文介绍了如何使用networkx 2.2中的社区模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前是这样使用这个模块的:

import community

if __name__ == '__main__':

    G = nx.karate_club_graph()
    pos = nx.spring_layout(G)

    partition = community.best_partition(G)

我安装了正确的模块:

sudo pip3 install python-louvain

我收到此错误:

AttributeError: module 'community' has no attribute 'best_partition'

据我所知,它遵循所提供的文档here

推荐答案

似乎其他一些人以前也遇到过这个问题,请参阅: https://bitbucket.org/taynaud/python-louvain/issues/23/module-has-no-attribute-best_partition

如果您安装了另一个名为Community的库,则可能会导致问题。以下是我链接的帖子中提出的一个解决方案:

from community import community_louvain
partition = community_louvain.best_partition(G)

这篇关于如何使用networkx 2.2中的社区模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆