Modifying kernelspec used at launch
See original GitHub issueI’m working on setting up a Jupyter notebook that uses the R kernel (IRkernel) inside a conda environment named contrib-viz
. When I launch the binder, the kernel is not found, as seen in the following screenshot
The problem seems to be that the local notebook is saved with a kernlespec that includes the name of the conda environment:
"kernelspec": {
"display_name": "R [conda env:contrib-viz]",
"language": "R",
"name": "conda-env-contrib-viz-r"
}
Jupyter launched through binder is trying to use a different kernelspec:
"kernelspec": {
"display_name": "R [conda env:conda]",
"language": "R",
"name": "conda-env-conda-r"
}
Selecting the kernel R [conda env:conda]
that is offered in the drop down menu in the screenshot is a workaround, but I expect that will deter novice users who would most benefit from the binder. I can also edit the .ipynb
file to make the kernelspec match what binder expects, but then I get the kernel not found error when I run the notebook in my local environment. Renaming my conda environment would probably work, but I have multiple environments for this project and prefer to keep them distinct if possible. Is there a better general solution?
The binder link is https://mybinder.org/v2/gh/agitter/meta-review/binder?filepath=analyses/deep-review-contrib/02.contrib-viz.ipynb This is a temporary branch for a pull request that will be deleted soon. Currently, this is the version with an edited .ipynb
file that works in binder but not locally.
Thanks for the binder service. I see a lot of opportunities to use this.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (7 by maintainers)
This is working now so I’ll leave some final notes for anyone who has a similar problem. I decided that modifying the
.ipynb
notebook file in thepostBuild
script was the best way to accomplish what I wanted. I can still usenb_conda_kernels
in my local environment. The modified notebook has an edited kernelspec to match a kernel that is available in Binder.I was unable to get
conda create --name new_name --clone old_name
working. I received the erroreven after briefly attempting to enable conda in
postBuild
. Becauseconda clean -tipsy
has already run before theconda create
in thepostBuild
script, creating the environment is slow anyway. conda has to re-download all of the packages again.Part of my initial confusion was already related to this issue https://github.com/jupyter/repo2docker/issues/411 I had assumed that using Binder with an
environment.yml
file would work similarly toAfter looking through the repo2docker conda buildpack code I realized that the environment in
environment.yml
is not created or activated. It is used to update the base conda environment. That could be documented in https://mybinder.readthedocs.io/en/latest/config_files.html#environment-yml and I’m happy to suggest something in another issue.The
environment.yml
is used to update the environment so even for packages that are installed by default the version specified in the repositoriesenvironment.yml
should “win”. Otherwise please report a bug in https://github.com/jupyter/repo2docker.The best we have to offer right now for running things locally is http://repo2docker.readthedocs.io/ which is the tool that Binder uses to build your environment. You can install it with
pip install jupyter-repo2docker
and runrepo2docker https://github.com/myorg/myrepo
to get the same experience as on mybinder.org (with some patience to build the image). For actual local developmentrepo2docker --editable some/local/dir
is more useful as it will mount your local directory read-write into the container so you can keep using your favourite editor and tools. Polishing the run-locally-for-day-to-day-dev experience is something we are working on and welcome contributions. IN particular in making things faster.