Binder fails to compile pygraphviz

Perhaps some more experienced folk know why Binder fails to build my repository of jupyter notebooks

my requirements.txt file reads:

rdflib>=5.0.0
networkx>=2.6.1
jupyter
graphviz
pygraphviz==1.7

My naive reading of the “Build Logs” (which, frustratingly, can’t be copy/pasted or otherwise stored) suggests that the following are relevant lines:

The build appears to successfully find and obtain pygraphviz;

Collecting pygraphviz--1.7
  Downloading pygraphviz-1.7.zip (118 kB)

however, I note that it is a zip file, not a .whl file like the other requirements are once found. For example:

Collecting rdflib>=5.0.0
  Downloading rdflib-5.0.0-py3-none-any.whl (231 kB)

Once the build process gets around to building pygraphviz, it fails saying:

Building wheel for pygraphviz (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:

followed by the log of the attempt to build pygraphviz …
ending thus:

error: command 'gcc' failed with exit status 1
----------------------------------------------
ERROR: Failed building wheel for pygraphviz

Is there anything I can do to persuade Binder to successfully compile this python module?

mybinder.org uses repodocker to build images. You can install and run that tool locally to debug your build.

That means pygraphviz isn’t available as a precompiled package for your platform, so instead a zip containing the source for that module is downloaded and compiled.

I just tried running %pip install pygraphviz in a running Binder session and saw a couple things.

By default it wanted to get version 1.6.

The install failed and among the errors the following:

Package libcgraph was not found in the pkg-config search path.

This makes me think you need some additional apt packages added. Usually I use the configuration file apt.txt to add these. See here about use of apt.txt.

Try adding apt.txt with the following content based on python - pip install pygraphviz: No package 'libcgraph' found - Stack Overflow

graphviz
libgraphviz-dev
pkg-config
2 Likes

It required a few more adjustments to the requirements.txt file, but adding apt.txt to the repo, exactly as suggested, worked exactly as hoped. Many thanks!

A few notes:

  • all of those packages are available on conda-forge
    • all work on all of the conda-forge platforms (including windows and MacOS ARM/M1) out of the box… without invoking a compiler at install time
      • like it or lump it, on MyBinder you’re already running in a conda environment, unless you write your own Dockerfile
  • basically never install jupyter, it brings in mountains of stuff (like qt) that will not improve your binder experience
    • usually, just jupyterlab or notebook are sufficient… and probably with a full minimum version so you don’t get… whatever is installed on binder (by mamba during the repo2docker build)

So a notional environment.yml would be:

channels:
  - conda-forge
dependencies:
  - jupyterlab >=3.0.16,<4 # or `notebook >=6.4,<7` if that's your thing
  - networkx >=2.6.1
  - python-graphviz        # this is the equivalent of pip's `graphviz`
  - pygraphviz ==1.7
  - rdflib >=5.0.0

This would do one mamba solve (instead of apt’s solver, then pip’s solver, then invoking gcc). This is going to be faster/have better cache characteristics than apt.txt + requirements.txt… and have been verified to work by the conda-forge maintainers… and very possibly be faster at runtime because of compiler tuning.

can’t be copy/pasted

If you select some rows, Ctrl+Shift+C will copy the selection, as will Ctrl+Right Click to get the context menu. But I agree, having a “download log” button would be swell. Heck, that could be done entirely in the browser without any server changes.

2 Likes