我曾经像这样使用这个模块:
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'
据我所知,它遵循 此处 提供的文档。
原文由 DanielTheRocketMan 发布,翻译遵循 CC BY-SA 4.0 许可协议
似乎其他人之前遇到过这个问题,请参阅: https ://bitbucket.org/taynaud/python-louvain/issues/23/module-has-no-attribute-best_partition
如果您安装了另一个名为 community 的库,这可能会导致问题。这是我链接到的线程中提出的一种解决方案: