Using Binder to Create Reproducible Jupyter Notebooks
Published:
Binder is a way to create reproducible computing environments and share them with others so they can work on, or explore the same project.
The easiest way to use Binder is to have the following:
- Github account
- Anaconda
Start by creating a new Conda Environment for your project
$ conda create --name <env_name> python=3.6 jupyter
$ conda activate <env_name>
This creates an environment with Python and Jupyter installed. When you use the activate
command, you jump into that environment. Any packages you download when that environment is activated will be downloaded to that environment and not to your default environment. This help prevent compatibility issues between different packages, and is a good idea when starting a new project in general.
Next create a folder and git repo for your project
$ mkdir <new_folder_name>
$ cd <new_folder_name>
$ git init
Now write some code! (for example a “README.md” file)
$ git add .
$ git commit -m "First commit"
Next, create a (public) repo on Github. After you’ve done that run the following commands:
$ git remote add origin <new_repo_url>
$ git push -u origin master
Now you can create your Jupyter Notebook, install any additional packages you need, and start coding away!
When you’re ready to distribute!
You need to generate an environment.yml
file for your conda environment. This is done easily by running the following in the activated environment:
$ conda env export --no-builds | grep -v "prefix" > environment.yml
That’s it! You’re basically done!
Now you’re ready to publish your code to Binder!
Fill out the requested fields (repo URL, branch (ex ‘master’), and optional path to a notebook. Then press ‘launch’ and sit back and wait–it can take a while to create the binder environment for the first time.
After the launcher finishes, you should have a link that you can distribute or a badge that you can embed in a markdown file!