Search code examples
pythongraphnetworkx

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


I just installed networkx(currently version 3.3) and I went to try their official sample code for drawing a graph with bfs layout. The code is as follow:

G = nx.path_graph(4)
pos = nx.bfs_layout(G, 0)

But I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[43], line 2
      1 G = nx.path_graph(8)
----> 2 pos = nx.bfs_layout(G, 0) 

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

Any help to fix this would be appreciated.


Solution

  • I finally fixed that with pip install --force-reinstall networkx.