26

I am trying to draw simple graph with networkx and Python.

This is my code:

import networkx as nx
import matplotlib.pyplot as plt
G = nx.complete_graph(5)
nx.draw(G, with_labels=True, font_weight='bold')
plt.show()

but I am getting the error

Message=random_state_index is incorrect
Source=***\PythonTest.py
StackTrace:
File "***\PythonTest.py", line 15, in <module>
  nx.draw(G, with_labels=True)

Python 3.7 64bit

OS Windows

networkx 2.2 ,2.3 or 2.5 have the same problem.

6 Answers 6

31

The problem is resolved if you update the latest decorator 5.0.9 version (June 2021)

pip install decorator==5.0.9 then reboot

1
  • 1
    tks for the advice, i've update decorator to 5.0.9, pip install decorator==5.0.9 then reboot notebook and it works.
    – prof_FL
    Commented Dec 2, 2021 at 2:39
14

It looks like the issue MAY be due to a new release of the decorator module. See here: https://github.com/networkx/networkx/issues/4718

Can you downgrade your version of decorator?

5
  • 1
    Or as discussed in your linked issue, wait a moment to upgrade to decorator >= 5.0.1.
    – Sparky05
    Commented Apr 2, 2021 at 15:07
  • 2
    Thanks, Downgrade matplotlib version to 2.2.3 and decorator to 4 solve problem
    – S.Shafie
    Commented Apr 2, 2021 at 17:29
  • 3
    As also discussed in the other related question and answer (stackoverflow.com/a/66922837/11339311), decorator 5.0.5 has fixed the error.
    – Sparky05
    Commented Apr 6, 2021 at 9:43
  • 1
    I had the problem with decorator 5.0.6, but upgrading to 5.0.9 fixed it.
    – devinbost
    Commented Aug 20, 2021 at 6:06
  • decorator 5.0.6 had the same problem. Upgrading to 5.0.10 fixed it. Commented Oct 20, 2021 at 17:54
3

Open anaconda prompt and type

conda update --all

.. and Enter, it installs stable packages which are most compatible.

1
  • Worked for me, thanks! Probably good thing to keep this in a separate env, just to be sure other code keeps working.
    – Dr.Ripper
    Commented Nov 15, 2021 at 22:03
3

Just update the decorater and networkx versions:

pip install --user decorator==4.3.0 # (ignore waring for availability of newer version)

pip install --user networkx==2.3

This worked for me.

0

I just created a new python 3.6 environment within Anaconda Prompt, and made sure my Jupyter Notebook could connect to that new environment.

Run your code in this new environment within Jupyter, and it should work. Doing this downgrades your versions of networkx and decorator, which solves the problem.

2
0

The error is due to the incompatibility of the decorator installation to that used in the "networkz" module. An update to the latest version of the decorator 5.1.1 solves the problem. Following is the code snippet.

pip install decorator --upgrade

pip install decorator==5.1.1

Not the answer you're looking for? Browse other questions tagged or ask your own question.