1   Introduction

This guide describes the procedure and steps I followed in order to install Raspian GNU/Linux on a Raspberry Pi 3 B+.

One of my goals here is to setup the Raspberry Pi for doing AI, machine learning, and data science in general on devices at the edge of the network. And, that explains the section, below in this document, on installing and setting up the Anaconda distribution of python with its great collection of data science packages.

Note that I'm on Linux. The first few steps (used to create a bootable micro-SD card) will be different if you are on a different operating system.

You will see repeated instructions, below, to reboot. They are likely not all necessary. Some are needed, and others are just a good way to check your progress and to make sure that things are proceeding without problems.

For my latest install, I used a 64 GB micro-SD card. Previously, I've used 32 GB micro-SD cards and had plenty of room.

2   Raspian installation and setup

Install Debian GNU/Linux (Raspian). Do the following:

  1. Determine the device -- Insert micro-SD card. Note the device, e.g. /dev/sdb. Use either of the following, before and after inserting the micro-SD card to determine which device the SD card is mounted as. Warning: You can destroy your hard drive if you get this wrong.

    • $ lsblk
    • $ df
  2. If the micro-SD card does not already contain a FAT file system, format the SD card to a FAT file system -- Do:

    $ mkfs.fat -I /dev/sdX        # Where X is the device, e.g. "sdb".
  3. Copy the Raspian image onto the SD card.

    You can find an image here: https://www.raspberrypi.org/documentation/installation/

    Write the image to the micro-SD card. For the image that I used, I did the following:

    $ sudo dd bs=4M if=2018-03-13-raspbian-stretch.img of=/dev/sdX conv=fsync
    $ sync
  4. Boot and install -- Insert the SD card containing the Raspian image into the Raspberry Pi; turn on the power; follow the prompts.

    Log on with default user name: "pi" and default password: "raspberry".

  1. Expand the file system. To do so, run the following: $ sudo raspi-config.

  2. Change the host name -- Use one of the following:

    • $ sudo raspi-config -- Changing the host name is under network options.
    • Or, in the main desktop menu, select Preferences / Raspberry Pi Configuration.

    Also see: https://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/

  3. Enabling ssh -- I use secure shell to do work on various machines connected to my network. Use $ sudo raspi-config to enable ssh. Changing the host name is under "Interfacing Options".


    $ sudo shutdown -r now

    Or, use the Raspberry Pi desktop menu to reboot.

  4. (Optional) Change the main user (name) -- By default, the name of the main user for a newly installed Raspian system is "pi" and its home directory is /home/pi. If you would rather choose your own name, then follow these instructions. In the text mode console, do:

    $ exec sudo -s
    $ cd /
    $ sudo usermod -l <new-name> -d /home/<new-name> -m pi


    When I did the above step, it failed and reported that a process was in use. I killed that process with something like the following: $ kill nnnn, where nnnn is the process number, and then repeated the usermod command.

  5. Update and upgrade -- Do:

    $ sudo aptitude update
    $ sudo aptitude full-upgrade


  6. Configuration -- host name, ssh, etc -- Run $ rasp-config.

  7. Configure the keyboard -- I'm a Vim user and like the escape key to be more handy. So, I swap caps lock and escape keys. To do so, replace this line in /etc/default/keyboard:


    If this does not work, there might be some conflict with ~/.config/lxkeymap.cfg.

  8. Update the Raspberry Pi firmware:

    $ sudo rpi-update


  9. (Recommended) Change your password. Use either $ sudo rasp-config or $ sudo passwd.

  10. Configure window appearance, the desktop, etc -- There are several tools that help with this:

    • Run the Raspberry Pi configuration tool from the command line: $ sudo raspi-config.
    • Under the main desktop menu, there is Preferences / Appearance Settings and there is also a tool to configure the mouse and keyboard. I installed xscreensaver (using aptitude), and that can also be configured under the main desktop menu.
    • And, since I'm running OpenBox as my desktop, I ran $ obconf from the command line. Among other things, that enabled me to choose a window theme, specify the number of virtual desktops, configure windows and the mouse, etc.

There are some installation guides and additional sources of information:

3   Python data science tools

The Anaconda distribution of Python provides a super collection of packages for data science (and a lot more). You can find out about it here:

Installing Anaconda Python and some of those data science packages for Python gives the Raspberry Pi the capability to do AI and machine learning on devices out at the edge of a local network (LAN), which has the potential for reducing some of the need to ship large volumes of data collected on those devices to some more central node for processing. You can find a list of packages that are available for Anaconda here: https://docs.anaconda.com/anaconda/packages/pkg-docs.

3.1   Installing Anaconda Python

Here are the steps I took to install Anaconda Python 3 on the Raspberry Pi 3 B+:

  1. Download the Miniconda distribution file. You can find it here:

    The one I used for Python 3 for the Raspberry Pi 3 B+ was here: https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh.

  2. Install it with the following:

    $ bash Miniconda3-latest-Linux-armv7l.sh

    Note that you must explicitly run bash.

    There are installation instructions here: https://docs.anaconda.com/anaconda/install/

    The installer picks a default location for the installation. If you want it somewhere else, specify a directory.

    Wait for the installation to finish.

  3. Activate the installed version. In my case I do this by sourcing the following file:

    # file: set-envir-anaconda3
    source \
            /home/dkuhlman/a1/Python/Anaconda/anaconda301/bin/activate \
    PS1='{ana3} \w [\#] '

    And, as a convenience, I have a bash alias that sources that file:

    alias se3='source ~/bin/set-envir-anaconda3'

    If you are on MS Windows, your activation will be different. See the install instructions referenced above.

  4. Update the Anaconda Python installation:

    $ conda update conda
    $ conda update --all
  5. Install additional packages as needed, for example:

    $ conda install ipython numpy scipy pandas
  6. I use IPython frequently. So, I create both an IPython default profile and another profile for the use of numpy, scipy, pandas, and other data science packages:

    $ ipython profile create
    $ ipython profile create scipy

    Then you can customize your startup by modifying .ipython/profile_xxx/ipython_config.py, for each environment. Or, possibly you will create a symbolic link to a common file.

    And, you can put custom startup scripts in .ipython/profile_xxx/startup/. For example, I have the following two scripts in my startup sub-directory, under profile_scipy:

    # 50-config.py
    import sys
    def pdir(obj):
        """Print information about obj, including `dir(obj)`."""
        if isinstance(obj, type):
            print('class: {}'.format(obj.__name__))
            print('instance class name: {}'.format(obj.__class__.__name__))
        if obj.__doc__:
            print('doc string: {}'.format(obj.__doc__))
            print('doc string: no doc string')
    def read_file_contents(filename):
        with open(filename, 'r') as infile:
            content = infile.read()
        return content
    version = 'Python {}.{}'.format(sys.version_info.major, sys.version_info.minor)
    xx = quit
    # 60-config.py
    import numpy as np
    import scipy as sp
    import pandas as pd

    And, then I have this bash alias to start IPython with the Scipy profile:

    alias ipys='ipython --profile=scipy'

3.2   Summary

There is lots more that you can do with Anaconda Python. For example, you might want to consider creating a virtual environment within your Anaconda installation, and then installing packages for special purposes within that virtual environment.