• Support
  • How to install PyGraphviz in a Django app?

My Django app uses PyGraphviz.

On the server I run into the same problem, that I had locally:
Running pip3 install pygraphviz leads to this error:

  ERROR: Failed building wheel for pygraphviz
Failed to build pygraphviz
ERROR: Could not build wheels for pygraphviz, which is required to install pyproject.toml-based projects

The problem is described on Stackoverflow, and the solution worked locally:
sudo apt-get install python-dev graphviz libgraphviz-dev pkg-config

I tried yum install python-dev graphviz libgraphviz-dev pkg-config on the server,
but unsurprisingly it tells me, that I have to be root for that. What can I do?

  • sean replied to this.

    Watchduck the dependencies are already installed but PyGraphviz wants a newer version.

    The workarounds are:

    • Use an older version of PyGraphviz...

      cd ~/apps/name_of_app
      source env/bin/activate
      pip install pygraphviz==1.6
    • ... or install a newer version of GraphViz in your home directory. PyGraphviz wants v2.46 so:

      mkdir -p ~/opt/src
      cd ~/opt/src
      curl -JLO https://gitlab.com/graphviz/graphviz/-/package_files/7097037/download
      tar xf graphviz-2.46.1.tar.xz
      cd graphviz-2.46.1
      ./configure --prefix=$HOME/opt
      make && make install
      export PATH=$HOME/opt/bin/:$PATH
      export CPPFLAGS="-I$HOME/opt/include $CPPFLAGS"
      export LDFLAGS="-L$HOME/opt/lib $LDFLAGS"
      cd ~/apps/name_of_app
      source env/bin/activate
      pip install pygraphviz
    4 months later
    Mastodon