tribbloid
tribbloid

Reputation: 3858

How to fix ModuleNotFoundError: No module named 'networkx.drawing'; 'networkx' is not a package

This is a short python script:

import matplotlib.pyplot as plt
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout

G = nx.DiGraph()

when it is executed by plain python it gave the following stacktrace:

Traceback (most recent call last):
  File "python/spikes/networkx.py", line 17, in <module>
    import networkx as nx
  File "/home/peng/git/mxnet-spike/python/spikes/networkx.py", line 18, in <module>
    from networkx.drawing.nx_agraph import graphviz_layout
ModuleNotFoundError: No module named 'networkx.drawing'; 'networkx' is not a package

What could possibly cause this? Is python interpreter defective?

Upvotes: 0

Views: 3412

Answers (1)

Klaus D.
Klaus D.

Reputation: 14404

You have named your file networkx.py. When importing networkx the local file has precedence over the installed package.

Just rename your networkx.py and make sure to delete your __pycache__ folder if there is one.

Upvotes: 4

Related Questions