Data Science on a Chromebook: How to run Jupyter, Python, & R locally in ChromeOS
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:
username@penguin:~$ sudo bash Miniconda3-latest-Linux-x86_64.sh
You’ll be prompted to read through the license:
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
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):
username@penguin:~$ sudo chown -R username /opt/miniconda3
That should do it for your conda installation. To get conda running, you can enter into the base environment by executing:
username@penguin:~$ source /opt/miniconda3/bin/activate
Optional: 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:
(base) username@penguin:~$ conda create --name conda_env (base) username@penguin:~$ conda activate conda_env (conda_env) username@penguin:~$ (conda_env) username@penguin:~$ conda config --add channels conda-forge
If you want to start within a conda environment every time you open your Terminal app, open your
~/.bashrc file in a text editor and add these three lines to the bottom:
source /opt/miniconda3/bin/activate # starts conda every time Terminal opens conda activate conda_env # activates conda sub-environment export XDG_RUNTIME_DIR="" # allows Chrome to open automatically when launching Jupyter
The first two lines aren’t strictly necessary, but the last line above should be added to your
~/.bashrc file if you plan on using Jupyter; thanks to Daniel Pomales for this suggestion.
4. Install Jupyter
However you choose to set up your own conda environments, once you’re in your favorite environment, install Jupyter and generate a config file:
(conda_env) username@penguin:~$ conda install jupyter (conda_env) username@penguin:~$ jupyter notebook --generate-config
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).
(conda_env) username@penguin:~$ conda install r-irkernel (conda_env) username@penguin:~$ conda install rpy2
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:
(conda_env) username@penguin:~$ jupyter notebook
If your browser fails to launch on its own, copy the token printed out in the console and append it to the following URL: http://penguin.linux.test:8888/tree?token=TOKEN_GOES_HERE
Launch a notebook and start coding! Keep in mind, with this setup, you’ll want to install new Python packages using conda (e.g.,
conda install numpy matplotlib pandas).