Data Science on a Chromebook: How to run Jupyter, Python, & R locally in ChromeOS
Mar 6, 2019 • A step-by-step guide to getting Jupyter up and running locally in the Linux container on your Chromebook.
This post will guide you through the process of setting up Jupyter, Python, and (optionally) R to run in the Linux container on your Chromebook. While I have a Pixelbook, I’ve had people tell me they’ve used this post to get Conda/Python/Jupyter running on machines with a humble 2GB of RAM and 16GB storage. So these instructions should work for almost any Chromebook on the market.
I will be using conda in this tutorial, which is an environment manager that is a bit more comprehensive than pip. You can even install RStudio and other development tools quite easily with conda. I don’t have time to do a full explainer here, but make sure you’re familiar with the basics before proceeding: conda documentation.
1. Enable Linux Apps
Go to your Chromebook’s system settings and scroll down to the bottom. You should see an option to enable Linux Apps (this shouldn’t matter what OS channel you’re on, so long as you have at least Chrome ~71):
Follow the prompts; at the end, your computer should automatically launch a new “Terminal” app, which you will now see in your app drawer (I always pin it to the dock right away).
2. Download Miniconda
Using your browser, go to conda’s website at the following link and select which version of Python you want to go with your conda distribution by default: https://conda.io/miniconda.html. Since Python 2 is officially being sunset at the point, I recommend you choose the most up-to-date version of Python 3 for Linux 64-bit systems (for me, this is Python 3.7).
Important! Once you’ve downloaded the installer, use the ChromeOS File Explorer to move the file (usually something like Miniconda3-latest-Linux-x86_64) into the “Linux Files” section of your device’s storage.
3. Install Miniconda
Open the Terminal and navigate (using cd) to where you placed the Miniconda installer. Once there, run the following command to install conda on your machine:
Just keep pressing enter until you are required to type yes:
Important! Different people will have different preferences about where exactly to install conda on their device; I’ve taken my cues from a couple of StackOverflow posts (here and here) on this topic, but know that this is by no means canonical.
When prompted to choose an installation location, I select /opt/miniconda3, as shown below:
Type yes when prompted to initialize Miniconda3 in your /root/.bashrc folder.
Once conda is installed, you’ll also want to set the right permissions for the folder so conda can add/remove packages (make sure you replace username in the snippet below; also replace /opt/miniconda3 with your install location if you specified a different folder):
That should do it for your conda installation. Next, we just need to install Jupyter and you’ll be crunching numbers in no time.
4. Setup a conda environment & install Jupyter
To get conda running you’ll want to enter into the base environment by executing source /opt/miniconda3/bin/activate. Also, not to get too far into conda-ception, but I will usually add a sub-environment within my base conda which I find easier to manage. This can be done, along with activating the sub-environment and adding the conda-forge distribution channel, using the commands below:
This creates a config file at ~/.jupyter/jupyter_notebook_config.py, which allows you to set a password and customize other aspects of your Jupyter instance (see the Jupyter documentation for more info).
4.5 For R users: install the Jupyter R kernel
You can run R notebooks in Jupyter, and you can even run R in Python notebooks using rpy2 and the %%R magic (see here for more details).
Note you may also need to install some Linux packages using apt-get to get this working properly. Look at any error codes you get when trying to run R; they usually tell you which packages are missing.
5. Launch Jupyter — do data science!
Once you’ve accepted all the installation prompts for Jupyter and it’s various dependencies, launch jupyter directly from the terminal: