Jupyter Notebooks — More Tricks!

Greg Werner
IllumiDesk
Published in
3 min readJun 6, 2017

Here are three more handy tips to use with Jupyter Notebook! If this is your first time here, be sure to check out parts one and two for more advice about how to make Jupyter Notebook work for you.

Toggling Between Versions of Python

Python 2.x and 3.x have different strengths. As a developer, you may have your own preferences, based on things like library support, comfort level and so on.

It’s relatively straightforward to use either Python 2.x or Python 3.x in the Jupyter Notebook. But if you’re working on an unusual project, you might want to change between the two.

That’s actually very simple for Jupyter Notebook to do, assuming you have the conda package manager installed already. Just create a new conda environment to use different kernels, like this:

# Python 2.7

conda create -n py27 python=2.7 ipykernel

# Python 3.5

conda create -n py35 python=3.5 ipykernel

When you restart the app, both kernels will be available. Make sure you activate (or deactivate) the kernel you (don’t) need:

source activate py27
source deactivate

You can also manually register kernels. For instance, this code will configure a Python 2.7 environment:

conda create -n py27 python=2.7

source activate py27

conda install notebook ipykernelipython kernel install — user

And if you’re working within Python 3.x and want to set up a 2.x kernel, you’d do it like this:

python2 -m pip install ipykernelpython2 -m ipykernel install — user

You can also use virtualenv and pip for this, as well.

Previewing a Jupyter Notebook with 3Blades’ File Manager

3Blades’ file manager, isn’t just good at managing project files — you can use it to preview Jupyter Notebooks directly from our user interface. The 3Blades team decided to leverage the wonderful commuter ReactJs component built by the wonderful folks at nteract. This component transforms Jupyter Notebooks’ json schema, client side, without having to spawn a Jupyter Notebook server, or depend on server side rendering from other services, such as an NBViewer server.

All you have to do is select a file with the *.ipynb extension and click on the view icon to immediately see your Jupyter Notebook:

Select a Jupyter Notebook file

And voilá! A Notebook view, including visualizations may be viewed and shared instantly:

See your Jupyter Notebook files (*.ipynb) come alive with one click!

Create, Disseminate, Collect and Grade Assignments

Are you a pedagogue? Jupyter Notebook allows you to build programming exercises, with room for free-written responses. But manually grading Notebooks can be tedious, especially when dealing with hundreds of submissions. Fret no more! Nbgrader is an official Jupyter Nbgrader contains several useful commands, including creating student versions of notebooks, disseminating these to students and collecting students’ responses. You can even use it to customize how the interface looks on your students’ end.

Nbgrader is a complicated tool, and for space reasons it won’t be fully discussed here. (Keep your eyes peeled for a series on nbgrader’s full functionality in the future.) However, one of the most innovative commands it involves is the autograde function. Automatically scoring students’ responses may seem unusual, but actually it’s very straightforward in the computer science world: Jupyter Notebook simply runs the written code and determines if it produces the anticipated response.

Good test writing with Jupyter Notebook means you should grade functions individually, write contingencies for edge cases, and be prepared to give partial credit for code that’s well-executed but doesn’t quite accomplish what you, the teacher, want. You can also use Jupyter Notebook’s autograde function to check if students are using a particular function for an assignment rather than solving it some other way.

--

--