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.

David Buck
  • 3,752
  • 35
  • 31
  • 35
S.Shafie
  • 263
  • 1
  • 3
  • 5

6 Answers6

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

Aqua_George
  • 434
  • 1
  • 5
  • 9
  • 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 Dec 02 '21 at 02: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?

Frodnar
  • 2,129
  • 2
  • 6
  • 20
3

Open anaconda prompt and type

conda update --all

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

Cheche
  • 1,456
  • 10
  • 27
  • Worked for me, thanks! Probably good thing to keep this in a separate env, just to be sure other code keeps working. – Dr.Ripper Nov 15 '21 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.

Mandraenke
  • 3,086
  • 1
  • 13
  • 26
Kishan Kumar
  • 81
  • 1
  • 4
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.

orian
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29979967) – David Medinets Oct 03 '21 at 01:00
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '21 at 02:12
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

Lakshmi
  • 26
  • 1