# Binder fails to compile pygraphviz

**URL:** <https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912>\
**Category:** repo help\
**Created:** [July 9, 2021, 5:40pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912 "2021-07-09T17:40:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjon](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jjon](https://discourse.jupyter.org/u/jjon)\
**Post date:** [July 9, 2021, 5:40pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912/1 "2021-07-09T17:40:34Z")

</div>

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

my requirements.txt file reads:

```auto
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;

```auto
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:

```auto
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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [July 9, 2021, 6:28pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912/2 "2021-07-09T18:28:37Z")

</div>

[mybinder.org](http://mybinder.org) uses [`repodocker`](https://github.com/jupyterhub/repo2docker) to build images. You can install and run that tool locally to debug your build.

> [@jjon](#):
>
> however, I note that it is a zip file, not a .whl file like the other requirements are once found. For example:

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.

---

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [July 9, 2021, 6:35pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912/3 "2021-07-09T18:35:45Z")

</div>

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:

```nohighlight
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](https://mybinder.readthedocs.io/en/latest/config_files.html#apt-txt-install-packages-with-apt-get) 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](https://stackoverflow.com/a/42315670/8508004:)

```nohighlight
graphviz
libgraphviz-dev
pkg-config

```

---

<div class="post-metadata">

**Author:** ![jjon](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jjon](https://discourse.jupyter.org/u/jjon)\
**Post date:** [July 9, 2021, 8:06pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912/4 "2021-07-09T20:06:13Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)\
**Post date:** [July 9, 2021, 9:10pm UTC](https://discourse.jupyter.org/t/binder-fails-to-compile-pygraphviz/9912/5 "2021-07-09T21:10:14Z")

</div>

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:

```yaml
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.
