No-sweat Jupyter notebook setup on Google Compute Engine

· Zach Ocean

So you want to putter around with some data using Jupyter Notebook, and you don’t want to be limited by your local machine’s specs or have your laptop fan sounding like a jet engine. Here’s a solution using Google Compute Engine that takes about 10 minutes to set up.

  1. Create the virtual machine. You can do this via the Google Cloud UI by following the tutorial here. There are a number of reasonable presets for machines you can use depending on your needs. This isn’t free, so please pay attention to the pricing for the instances you request.

  2. Install Jupyter and start the notebook server by running jupyter notebook. By default my install starts the server on port 5000.

  3. Set up a secure channel for port forwarding from your local machine to the VM:

    $ gcloud compute ssh <your-vm-name> -- -L 5000:localhost:5000 -NT

The key here is the -L flag, which forwards connections on localhost:5000 over the secure channel to port 5000 on the remote machine.

Now you should be able to access your notebook server at http://localhost:5000. If you’re nervous about costs—e.g. perhaps you’ve added a GPU to your VM, which substantially cranks up the hourly rate—you can manually stop the virtual machine while you’re not using it, and restart it when you need it.