Search code examples
pythonnetwork-programmingpipnetworkximporterror

networkx ImportError: cannot import name _distributor_init


I was trying to use networkx library in my program. It ran well with no complaints at all. But now it suddently starts to complain though I didn't make any change to the program. Very weird. I have tried to reinstall networkx and numpy, but the system just says they are satisfied.

Traceback (most recent call last):
  File "degree_discount.py", line 4, in <module>
    import networkx as nx 
  File "/home/jessy/venv/local/lib/python2.7/site-packages/networkx/__init__.py", line 98, in <module>
    import networkx.utils
  File "/home/jessy/venv/local/lib/python2.7/site-packages/networkx/utils/__init__.py", line 3, in <module>
    from networkx.utils.random_sequence import *
  File "/home/jessy/venv/local/lib/python2.7/site-packages/networkx/utils/random_sequence.py", line 16, in <module>
    import random
  File "/home/jessy/random.py", line 9, in <module>
    import numpy as np
  File "/home/jessy/venv/local/lib/python2.7/site-packages/numpy/__init__.py", line 140, in <module>
    from . import _distributor_init
ImportError: cannot import name _distributor_init

Solution

  • I figured this out. I created a python file called 'random.py'. And I had "import random" in my degree_discount.py, so I guess python was confused.