# Creating a binder for a repository containing both setup.py and environment.yaml

**URL:** <https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232>\
**Category:** repo help\
**Tags:** help-wanted\
**Created:** [March 6, 2021, 5:18pm UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232 "2021-03-06T17:18:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cosimoNigro](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/cosimonigro/32/3905_2.png) [@cosimoNigro](https://discourse.jupyter.org/u/cosimoNigro)\
**Post date:** [March 6, 2021, 5:18pm UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232/1 "2021-03-06T17:18:43Z")

</div>

Dear Binder aficionados,

I created a [binder](https://mybinder.org/v2/gh/cosimoNigro/agnpy/HEAD) for my [python package hosted on GitHub](https://github.com/cosimoNigro/agnpy).

In a couple of days I am giving a tutorial and would like people to run the notebooks inside `docs/tutorials` in the repo.

The problem is the following: a couple of notebooks show how to wrap my package with an external package that is not part of the core dependencies (sherpa).  
Being not among the core dependencies, and hence not in the `setup.py`'s `install_requires`, the binder image (relying on the `setup.py`) was built without this additional package.

In order to solve this I created an `environment.yaml` (it’s in the repo) containing this additional external dependency. Still, when I re-launch binder, the `setup.py` and not the `environment.yaml` is used. Therefore I cannot execute in binder my example notebooks with the wrapper - the additional package is missing.

**Any suggestion? Is there a way to specify to binder which build method has to be used?**

I know you can add optional dependencies in `setup.py`, I am not sure though binder will run the appropriate extra command (e.g. `python setup.py[with_sherpa]`) when building.

Many thanks in advance,  
Cosimo

---

<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:** [March 6, 2021, 6:37pm UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232/2 "2021-03-06T18:37:01Z")

</div>

The easiest would be to put the follwoing towards the top of your notebooks demonstrating wrapping:

```python
%pip install sherpa

```

I assume it is Python package based on the description, but if it needs conda substitute `conda` in place of `pip`.

That way it runs before you need it and install it in the session environment at that time.

* * *

The other way would be to make a `binder` directory and put your `environment.yml` file there and specify installing your package there via addition of pip to `environment.yml`. [Here’s an example](https://github.com/fomightez/hhsuite3-binder) of using pip in `environment.yml` that just happens to be one I have handy. Putting configuration files outside of root is covered in the documentation [here](https://mybinder.readthedocs.io/en/latest/about/about.html?highlight=root#can-i-put-my-configuration-files-outside-the-root-of-my-repository).

---

<div class="post-metadata">

**Author:** ![cosimoNigro](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/cosimonigro/32/3905_2.png) [@cosimoNigro](https://discourse.jupyter.org/u/cosimoNigro)\
**Post date:** [March 8, 2021, 9:11am UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232/3 "2021-03-08T09:11:53Z")

</div>

Thanks for your help @fomightez!  
The `environment.yaml` was ignored because the extension accepted by Binder is `.yml`.  
Renaming `environment.yaml` to `environment.yml` fixed it.  
And actually the `environment.yml` takes precedence over the `setup.py`.

Thanks

---

<div class="post-metadata">

**Author:** ![nthiery](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/nthiery/32/604_2.png) [@nthiery](https://discourse.jupyter.org/u/nthiery)\
**Post date:** [March 8, 2021, 12:28pm UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232/4 "2021-03-08T12:28:12Z")

</div>

I routinely use repos with an environment.yml specifying “.” as  
pip dependency, which triggers the setup.py. See e.g.:

> **[binder · master · Info111 / ComputerLab](https://gitlab.u-psud.fr/Info111/ComputerLab/tree/master/binder)**
>
> Utilities for deploying the course for the students: computer lab, JupyterHub, binder, ...

Would that work for you?

---

<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:** [March 8, 2021, 2:11pm UTC](https://discourse.jupyter.org/t/creating-a-binder-for-a-repository-containing-both-setup-py-and-environment-yaml/8232/5 "2021-03-08T14:11:24Z")

</div>

Yes, I was considering putting my concern of you talking about `.yaml` in my reply; however, when I looked I thought you had fixed it already, and so I thought the issue may have remained. Still, the issues your post raised are good concepts to discuss and have examples highlighted on this forum.
