Install Graphviz and pygraphviz without root privilege

Yu Yang
2 min readJun 26, 2022

In the official installation documentation of pygraphviz, it is suggested that we install Graphviz first with sudo apt-get install graphviz graphviz-dev . However, for users like me who don’t have root privilege on the server, this command just doesn’t work! This article is to help users like me to solve this problem. I will give a step-by-step guidance on how to install Graphviz and install pygraphviz afterwards.

1. Install Graphviz from source

Go to the Graphviz official website to download the source file. You may choose whatever version you prefer, in this paper, I choose the 2.46.0 version: graphviz-2.46.0.tar.gz.

# install Graphviz from source
wget https://gitlab.com/graphviz/graphviz/-/package_files/6163716/download
# unzip the source code
tar -xf download
# create a folder to save graphviz locally
mkdir ~/usr/local/graphviz
# go the graphviz folder
cd graphviz-2.46.0
# configure the installation
./configure — prefix ~/usr/local/graphviz
# install.
# (1) You might see warning messages, but that is just C++ being picky about code, no worries.
# (2) If error shows that cannot find `Python.h`, then add the python lib path in your virtual environment.
make
CPATH=[your_env]/include/python3.8 make install

2. Configure the environment variables.

Add the following two lines to your ~/.bashrc file.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/usr/local/graphviz/lib
export PATH="$HOME/usr/local/graphviz/bin:$PATH"

3. Check the installation of Graphviz

# check the version
dot -V
# run a test example: if output.svg shows up, then you are all set.
echo 'digraph { a -> b }' | dot -Tsvg > output.svg

4. Install pygraphviz

Now, you can simply run pip install pygraphviz to install the package. In the case where you cannot use pip freely, try installing it from source as follows.

# download source code: either the stable or the developing version
wget https://github.com/pygraphviz/pygraphviz/archive/refs/tags/pygraphviz-1.9.tar.gz
# unzip and change directory to the source code
tar -xf pygraphviz-1.9.tar.gz
cd pygraphviz-pygraphviz-1.9
# install from source
python -m pip install . --global-option=build_ext --global-option="-I~/usr/local/graphviz/include" --global-option="-L~/usr/local/graphviz/lib"
# check the installation status
python -c "import pygraphviz as pgv"

Great! Now you are set! Enjoy your journey with the pygraphviz package!

--

--