Network X (4.8.2)
When I tried, http://networkx.lanl.gov/ was not available. I used http://networkx.github.io to read documents instead.
For installation, I dis as follows. sudo was required because of authorization problem.
$ sudo pip install networkx Password: Downloading/unpacking networkx Downloading networkx-1.7.zip (1.0MB): 1.0MB downloaded Running setup.py egg_info for package networkx warning: no files found matching 'scripts/*' warning: no files found matching 'networkx/tests/*.txt' warning: no files found matching 'networkx/*/*/tests/*.txt' warning: no previously-included files matching '*~' found anywhere in distribution warning: no previously-included files matching '*.pyc' found anywhere in distribution warning: no previously-included files matching '.svn' found anywhere in distribution no previously-included directories found matching 'doc/build' no previously-included directories found matching 'doc/source/reference/generated' no previously-included directories found matching 'doc/source/examples' no previously-included directories found matching 'doc/source/static/examples' no previously-included directories found matching 'doc/source/templates/gallery.html' Installing collected packages: networkx Running setup.py install for networkx deleting networkx.egg-info/requires.txt warning: no files found matching 'scripts/*' warning: no files found matching 'networkx/tests/*.txt' warning: no files found matching 'networkx/*/*/tests/*.txt' warning: no previously-included files matching '*~' found anywhere in distribution warning: no previously-included files matching '*.pyc' found anywhere in distribution warning: no previously-included files matching '.svn' found anywhere in distribution no previously-included directories found matching 'doc/build' no previously-included directories found matching 'doc/source/reference/generated' no previously-included directories found matching 'doc/source/examples' no previously-included directories found matching 'doc/source/static/examples' no previously-included directories found matching 'doc/source/templates/gallery.html' Successfully installed networkx Cleaning up... $
Write following code and saved as name 'exnetworkx.py'.
import networkx as nx import matplotlib from nltk.corpus import wordnet as wn def traverse(graph, start, node): graph.depth[node.name] = node.shortest_path_distance(start) for child in node.hyponyms(): graph.add_edge(node.name, child.name) traverse(graph, start, child) def hyponym_graph(start): G = nx.Graph() G.depth = {} traverse(G, start, start) return G def graph_draw(graph): nx.draw_graphviz(graph, node_size = [16 * graph.degree(n) for n in graph], node_color = [graph.depth[n] for n in graph], with_labels = False) matplotlib.pyplot.show()
Then try to draw a graph.
>>> import exnetworkx >>> from exnetworkx import * >>> dog = wn.synset('dog.n.01') >>> graph = hyponym_graph(dog) >>> graph_draw(graph) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/ken/Documents/workspace/NLTK Learning/scripts/exnetworkx.py", line 21, in graph_draw with_labels = False) File "/Library/Python/2.7/site-packages/networkx/drawing/nx_pylab.py", line 888, in draw_graphviz pos=nx.drawing.graphviz_layout(G,prog) File "/Library/Python/2.7/site-packages/networkx/drawing/nx_agraph.py", line 229, in graphviz_layout return pygraphviz_layout(G,prog=prog,root=root,args=args) File "/Library/Python/2.7/site-packages/networkx/drawing/nx_agraph.py", line 260, in pygraphviz_layout '(not available for Python3)') ImportError: ('requires pygraphviz ', 'http://networkx.lanl.gov/pygraphviz ', '(not available for Python3)') >>>
It seems 'pygraphviz" is required. Let's install via pip.
$ pip install pygraphviz Downloading/unpacking pygraphviz Running setup.py egg_info for package pygraphviz /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found Trying pkg-config Trying dotneato-config Failed to find dotneato-config Your Graphviz installation could not be found. 1) You don't have Graphviz installed: Install Graphviz (http://graphviz.org) 2) Your Graphviz package might incomplete. Install the binary development subpackage (e.g. libgraphviz-dev or similar.) 3) You are using Windows There are no PyGraphviz binary packages for Windows but you might be able to build it from this source. See http://networkx.lanl.gov/pygraphviz/reference/faq.html If you think your installation is correct you will need to manually change the include_path and library_path variables in setup.py to point to the correct locations of your graphviz installation. The current setting of library_path and include_path is: library_path=None include_path=None Traceback (most recent call last): File "<string>", line 16, in <module> File "/private/var/folders/z_/45w_7yf1701gxyghp070g5t40000gn/T/pip-build-ken/pygraphviz/setup.py", line 89, in <module> raise OSError,"Error locating graphviz." OSError: Error locating graphviz. Complete output from command python setup.py egg_info: /bin/sh: pkg-config: command not found /bin/sh: pkg-config: command not found Trying pkg-config Trying dotneato-config Failed to find dotneato-config Your Graphviz installation could not be found. 1) You don't have Graphviz installed: Install Graphviz (http://graphviz.org) 2) Your Graphviz package might incomplete. Install the binary development subpackage (e.g. libgraphviz-dev or similar.) 3) You are using Windows There are no PyGraphviz binary packages for Windows but you might be able to build it from this source. See http://networkx.lanl.gov/pygraphviz/reference/faq.html If you think your installation is correct you will need to manually change the include_path and library_path variables in setup.py to point to the correct locations of your graphviz installation. The current setting of library_path and include_path is: library_path=None include_path=None Traceback (most recent call last): File "<string>", line 16, in <module> File "/private/var/folders/z_/45w_7yf1701gxyghp070g5t40000gn/T/pip-build-ken/pygraphviz/setup.py", line 89, in <module> raise OSError,"Error locating graphviz."