CuriousS
CuriousS

Reputation: 126

Networkx is unable to find some packages (version 1.10)

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

    >>> nx.min_maximal_matching
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'min_maximal_matching'
    >>> nx.__version__
    '1.10'

Just to do a sanity check, I tried with another method from the same group of function, (approximation packages), and it worked,

    >>> nx.node_connectivity
    <function node_connectivity at 0x10b517410>

Thanks! PS: I am using python 2.7.8

Upvotes: 4

Views: 578

Answers (1)

unutbu
unutbu

Reputation: 880707

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.

Upvotes: 4

Related Questions