Networkx is unable to find some packages (version 1.10)

前端 未结 1 1094
轮回少年
轮回少年 2021-01-13 14:02

I am using networkx for computation of min_maximal_matching, It gave the following error, I did a pip install networkx --upgrade, and on vers

相关标签:
1条回答
  • 2021-01-13 14:52

    The function is not exposed in the netxwork namespace, but if you import networkx.algorithms.approximation, then you'll find it there:

    In [311]: import networkx.algorithms.approximation as naa
    
    In [312]: naa.min_maximal_matching
    Out[319]: <function networkx.algorithms.approximation.matching.min_maximal_matching>
    

    I found this by following the link you provided to the min_maximal_matching doc page to the source code.

    The source code makes it clear where the function is defined: networkx.algorithms.approximation.matching.

    The networkx/algorithms/approximation/__init__.py file imports everything in the networkx.algorithms.approximation.matching namespace into the networkx.algorthims.approximation namespace:

    from networkx.algorithms.approximation.matching import *
    

    and this is why you can stop after importing

    import networkx.algorithms.approximation as naa
    

    instead of having to drill down even farther, as in

    In [307]: import networkx.algorithms.approximation.matching as naam
    
    In [308]: naam.min_maximal_matching
    Out[310]: <function networkx.algorithms.approximation.matching.min_maximal_matching>
    

    although, as you can see, that also works.

    0 讨论(0)
提交回复
热议问题