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()

#%%

networkx ImportError: cannot import name 'graphviz_layout'_第1张图片

你可能感兴趣的:(python,networkx)