Install PyGraphViz

Install PyGraphViz with all required dependencies.

Written by pavan.kumarchalamcharla

Last published at: May 11th, 2022

PyGraphViz Python libraries are used to plot causal inference networks.

If you try to install PyGraphViz as a standard library, it fails due to dependency errors.

PyGraphViz has the following dependencies:

  • python3-dev
  • graphviz
  • libgraphviz-dev
  • pkg-config

Install via notebook

  1. Install the dependencies with apt-get.
    %sh
    
    sudo apt-get install -y python3-dev graphviz libgraphviz-dev pkg-config
  2. After the dependencies are installed, use pip to install PyGraphViz.
    %sh
    
    pip install pygraphviz

Install via init script

  1. Create the init script.
    %python
    
    dbutils.fs.put("dbfs:/databricks/<init-script-folder>/install-pygraphviz.sh",
    """
    #!/bin/bash
    #install dependent packages
    sudo apt-get install -y python3-dev graphviz libgraphviz-dev pkg-config
    pip install pygraphviz""", True)
  2. Install the init script that you just created as a cluster-scoped init script (AWS | AzureGCP).
    You will need the full path to the location of the script (dbfs:/databricks/<init-script-folder>/install-pygraphviz.sh).
  3. Restart the cluster after you have installed the init script.