Search code examples
pythongraphvizgoogle-cloud-datalab

Cannot use graphviz in Google Cloud Datalab


This is a tutorial about visualizing network diagrams using Google Cloud Datalab.

Everything worked perfectly (needs to change "gcp.bigquery" to "datalab.bigquery" in [25]) until:

In [35]:

%%bash
/usr/bin/yes | apt-get install graphviz
pip install --upgrade graphviz
/usr/bin/yes | pip uninstall pyparsing
pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz
pip install --upgrade pydot

Once I uninstalled pyparsing, the pip command cannot work and the next 2 lines cannot be executed correctly.

If I ignore the lines related to pyparsing, just install/upgrade graphviz and pydot, an error will occur at this line in "In [67]:" :

pos=nx.graphviz_layout(gmax, prog='circo')

AttributeError: 'module' object has no attribute 'graphviz_layout'

I don't think it is a pyparsing matter. Maybe the graphviz version is the point, since this tutorial was written about 2 years ago.

Any idea about it?

Thanks


Solution

  • The network graph displayed correctly after I changed

    pos=nx.graphviz_layout(gmax, prog='circo')
    

    to

    pos=nx.nx_pydot.graphviz_layout(gmax, prog='circo')
    

    based on this StackOverflow post. This required pydotplus so I also updated one of the cells with %%bash. I ran

    %%bash
    apt-get update
    apt-get install -y graphviz
    pip install pydot
    pip install graphviz
    pip install pydotplus
    

    instead of

    %%bash
    /usr/bin/yes | apt-get install graphviz
    pip install --upgrade graphviz
    /usr/bin/yes | pip uninstall pyparsing
    pip install -Iv https://pypi.python.org/packages/source/p/pyparsing/pyparsing-1.5.7.tar.gz
    pip install --upgrade pydot
    

    I hope this helps!