Setting up a Chromebook for Python programming

We can now use Chromebooks for data science or quantitative research using Chromebooks with the introduction of Linux Debian distribution via the Crostini add-on in Chrome OS! This provides us with a hybrid solution of being able to perform intitial data explorations and training simple models locally before transitioning to Google CoLab for more heavy duty number crunching! See my post on Introduction to Google Colab for more details.

This will run through the steps used setup the Pixelbook / Chromebook (I have Pixelbook) for programming in Python using the Anaconda Distribution. It assumes general knowledge of the below:

  • Basic general knowledge of Linux systems (i.e., changing directories, listing all files in directories)

  • Use of a Linux editor (i.e., vim).

Installing Linux Debian (i.e., Crostini) on the Pixelbook

  • Go to Settings in your Pixelbook and scroll/search to Linux (Beta).

  • Toggle the Linux Apps for Chrome Book option. This will install the Terminal program on to your Pixelbook.

  • Terminal is your access point into the Linux Debian system in the Pixelbook.

Customizing the Crostini installation

These are the customizations that I use on my Pixelbook Crostini. You don't need to follow any of these customizations, and if you have other cool things you do with your personal Chromebook Crostini setup feel free to share them with me!

Include stretch_backports to your Crostini distribution

  • Include stretch-backports to the Crostini Virtual Machine (VM) version of debian stretch by updating the source.list

$  sudo vim /etc/apt/sources.list
  • Add the following the backports repository at the bottom.

# Backports repository
deb stretch-backports main contrib non-free

Update your Linux installation

  • Download the Linux Debian updates and upgrade and installs them. apt-get downloads the package lists from the repositories and 'updates' them to get information on the newest version of packages and their dependences. dist-upgrade actually performs the install of the latest packages and handles dependencies intelligently.

$ sudo apt-get update && sudo apt-get dist-upgrade

Install tree

  • Make directory structures look nicer by installing tree.

$ sudo apt install tree
$ tree -d

Install fonts-powerline

  • Making fonts look nicer in terminal by installing fonts-powerline.

$ sudo apt -t stretch-backports install fonts-powerline

Install tmux

  • Install tmux, a terminal multiplexer.

$ sudo apt -t stretch-backports install tmux
  • Customize tmux by adding .tmux.conf in your home directory and add the following

# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

Make ChromeOS shortcuts function in Terminal

  • To make the ChromeOS shortcuts function in Terminal, press Ctrl-Shift-p in Terminal.
    • This will open the Profile settings for Terminal in the Chrome Browser.

    • Scroll to keybindings and enter the following

  "Alt-187": "PASS",
  "Alt-189": "PASS",
  "Alt-219": "PASS",
  "Alt-221": "PASS",
  "Ctrl-Shift-W": "PASS"

Install nodejs

  • Install nodejs as you need this for tldr and for Jupyter Lab.

$ curl -sL | sudo -E bash -
$ sudo apt-get install -y nodejs
$ sudo apt-get install -y build-essential
  • tldr is a short and useful help page for commands. Upon installing, we need to update it to the latest manual. We can then test it with to see the concise help file for the conda command.

$ sudo npm install -g tldr
$ tldr --update
$ tldr conda

Downloading & installing the Anaconda Distribution of Python

  • Go to the Anaconda website and download the 3.X.X version of Python for Linux. This will download an into your downloads folder.

  • Go to the Files app in Chrome OS and transfer the file from Downloads into the Linux files folder.

  • Open Terminal in your Pixelbook and ensure that you are in your home directory (i.e., /home/USERNAME)

  • Install the Anaconda Python distribution.

$ bash`
  • When prompted, install VSCode too (i.e., Microsoft Visual Studio Code).

Adding Anaconda3 distribution to the Linux PATH

  • Open Terminal and check that you are in your home directory (i.e., /home/USERNAME)

  • Use the vim editor to open the .bashrc file.

$ vim .bashrc
  • Add the following line into the .bashrc file and save. This line will add the Anaconda Python executable files into your Linux PATH.

export PATH="/home/<USERNAME>/anaconda3/bin/:$PATH"
  • Rerun the .bashrc file.

$ source .bashrc
  • Activate the Python environment to check that you have successfully added Anaconda Python execuable files into your Linux PATH.

$ source activate root

Setting up Jupyter Lab

  • Open Terminal.

  • Obtain the ip address of your Linux Crostini terminal

$ ip addr
  • Analyze output below.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
   valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:16:3e:4f:42:95 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet brd scope global eth0
   valid_lft forever preferred_lft forever
inet6 fe80::216:3eff:fe4f:4295/64 scope link
   valid_lft forever preferred_lft forever
  • Record the second ip address which is in the 'Broadcast' section. For my system it is but it will be different for yours. We will continue to use my ip address as an example.

  • Generate a in the director /home/<user>/.jupyter/.

$ jupyter notebook --generate-config
  • In the /home/<user>/.jupyter/, open the file by using vim and update the following lines:

c.NotebookApp.allow_origin ='*' #allow all origins
c.NotebookApp.ip = '' # listen to specific IP address
  • Alternatively, you can request that the NoteBookApp.ip listens to all IP addresses (less secure)

c.NotebookApp.allow_origin ='*' #allow all origins
c.NotebookApp.ip = '*' # listen to all IP addresses
  • You're now ready to start programming in Python on your Pixelbook! Feel free to use any of the following commands in Terminal:

$ jupyter lab
$ jupyter notebook
$ spyder
$ anaconda-navigator
  • I usually use Spyder for serious development and switch between Jupyter Lab and Jupyter `Notebook for creating the coding blog posts. anaconda-navigator is a GUI for interfacing with your conda environments and packages.

  • If you need more powerful computing resources, I recommend the use of Google Colab. See my post on Hybrid machine learning with Colab for more details.


Comments powered by Disqus