Search code examples
pythonnetworkx

networkx cannot import name 'create_degree_sequence'


Python library networkx has a function create_degree_sequence. It appears in several answers, such as this: Example.

I am using networkx version 2.6.3.

When I try to import the function, I get this error: cannot import name 'create_degree_sequence' from 'networkx.utils' I have not found where the function was moved to in the documentation. Is the function still available? Was it replaced with another function?

import networkx
from networkx.utils import powerlaw_sequence
from networkx.utils import create_degree_sequence

num = 100
exp = 2.5
sequence = create_degree_sequence(num, powerlaw_sequence, exponent=exp)
cannot import name 'create_degree_sequence' from 'networkx.utils' 

https://stackoverflow.com/a/28969892/814438


Solution

  • Yes, this function seems to have been replaced. The latest equivalent is the configuration_model function, which can be imported with from networkx import configuration_model.