networkx ImportError: cannot import name 'graphviz_layout'

networkx ImportError: cannot import name ‘graphviz_layout’

先看

  1. https://github.com/CristiFati/Prebuilt-Binaries/blob/master/Windows/PyGraphviz/Readme.md
  2. https://blog.csdn.net/ty_0930/article/details/87438962
  3. https://networkx.github.io/documentation/networkx-1.9/examples/drawing/circular_tree.html
  4. https://stackoverflow.com/questions/33433274/anaconda-graphviz-cant-import-after-installation
  5. http://www.mamicode.com/info-detail-2422004.html

看完了都解决不了怎么办

# pip show networkx
Name: networkx
Version: 2.3
Summary: Python package for creating and manipulating graphs and networks
Home-page: http://networkx.github.io/
Author: Aric Hagberg
Author-email: hagberg@lanl.gov
License: BSD
Location: c:\python36\lib\site-packages
Requires: decorator
Required-by:

原来 graphviz_layout 在2.3中换成nx.nx_agraph.graphviz_layout

https://networkx.github.io/documentation/stable/tutorial.html#drawing-graphs

pos = nx.nx_agraph.graphviz_layout(G)

#%%
import networkx as nx
import matplotlib.pyplot as plt

# try:
#    from networkx import graphviz_layout
# except ImportError:
#     raise ImportError("This example needs Graphviz and either PyGraphviz or Pydot")

#%%
G=nx.balanced_tree(3,5)
#pos=nx.graphviz_layout(G,prog='twopi',args='')
pos = nx.nx_agraph.graphviz_layout(G,prog='twopi',args='')
plt.figure(figsize=(8,8))
nx.draw(G,pos,node_size=20,alpha=0.5,node_color="blue", with_labels=False)
plt.axis('equal')
#plt.savefig('circular_tree.png')
plt.show()

#%%

在这里插入图片描述

`ImportError: DLL load failed while importing _graphviz: 找不到指定的模块` 这个错误通常发生在尝试导入 Python 中的 `graphviz` 模块时。`_graphviz` 是内部使用的模块名,用于加载 Graphviz 库的动态链接库(DLL),这通常发生在 Windows 平台上。 这个错误意味着系统无法找到 Graphviz 的动态链接库文件。原因可能有以下几个: 1. **Graphviz 安装路径未添加到系统环境变量**:确保 Graphviz 可执行文件的目录已经被添加到了系统的 `PATH` 环境变量里。你可以通过命令提示符运行 `echo %PATH%` 来查看当前的 `PATH` 是否包含 Graphviz 目录。 2. **缺少 Graphviz 的 DLL 文件**:如果 Graphviz 已经安装,但是特定的 DLL 文件缺失,也可能导致此问题。Graphviz 安装时会创建一些 DLL 文件用于与 Python 集成,例如 `libgraphviz.dll` 或其他相关文件。确保所有必需的 DLL 都存在于预期的位置(通常是 `%ProgramFiles%\Graphviz\bin`)。 3. **Python 版本与 Graphviz 版本兼容性问题**:有时可能是 Python 和 Graphviz 的版本之间存在兼容性问题。建议检查两者版本,并确认是否已安装了针对当前 Python 版本的 Graphviz 版本。 4. **依赖于版本的库**:如果你使用的是某些第三方库(如 `pydot` 或 `networkx` 等),它们可能也有特定的依赖项需要正确配置。确保这些库也能够正常访问 Graphviz 的 DLL 文件。 解决这个问题的基本步骤包括: - **检查安装路径**:确认 Graphviz 是否正确安装,并位于系统 PATH 路径内。 - **检查 DLL 存在性**:手动搜索或使用文件管理工具验证关键的 DLL 文件是否存在。 - **更新或回滚软件**:如果是特定版本问题,则考虑升级至最新版本或回到先前已知能正确工作的版本。 - **重新安装 Graphviz**:有时候卸载并重新安装 Graphviz 可以解决由于路径或注册表错误引起的此类问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值