在使用networkx时,有时候会出现报错
random_state_arg = args[random_state_index]
IndexError: tuple index out of range
这是因为decorator版本较高,与networkx不匹配,只需要降低decorator的版本,一般来说如下即可:
pip install decorator==4.4.2
相关:Networkx是一个Python包,用于创建、操作和研究复杂网络的结构、动态和功能。参见:https://networkx.github.io完整的文档。
然后这样了,安装成功了。
>>
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting decorator==4.4.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ed/1b/72a1821152d07cf1d8b6fce298aeb06a7eb90f4d6d41acec9861e7cc6df0/decorator-4.4.2-py2.py3-none-any.whl (9.2 kB)
DEPRECATION: pyodbc 4.0.0-unsupported has a non-standard version number. pip 24.1 will enforce this behaviour change. A possible replacement is to upgrade to a newer version of pyodbc or contact the author to suggest that they release a version with a conforming version number. Discussion can be found at https://github.com/pypa/pip/issues/12063
Installing collected packages: decorator
Attempting uninstall: decorator
Found existing installation: decorator 5.0.6
Uninstalling decorator-5.0.6:
Successfully uninstalled decorator-5.0.6
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
spyder 4.2.5 requires pyqt5<5.13, which is not installed.
spyder 4.2.5 requires pyqtwebengine<5.13, which is not installed.
Successfully installed decorator-4.4.2
续写:
在降低decorator版本之后,依旧不显示networkx的绘图,有可能时networkx和matplotlib版本不兼容,而且我使用的时anoconda3的base python3.8,这时候只需要更新conda中networkx和matplotlib到最新版本即可。
在conda环境中,要更新networkx和matplotlib(通常用于绘图,缩写为plt)到最新版本,使用以下命令:
conda update networkx
conda update matplotlib