RASPBERRY PI + IPAD
Welcome back, folks! We’re back again with our third and possibly final post in enabling a Raspberry Pi to work with an iPad Pro for data science work. If you’ve been following along so far, then you will already be able to connect the Raspberry Pi to your iPad Pro with a direct USB-C to USB-C connection. In case you missed those first two posts that have gotten us tho this point, here they are again:
In this post, we’re going to cover getting all our data science tools installed onto the Pi properly. In case you are unaware, the Raspberry Pi’s CPU makes use of an ARM architecture while many other modern computers use an x86 architecture. Don’t worry, you don’t need to know what those exactly mean, but it’s to say that installing some things can be a bit unconventional.
Alright, we have a lot of ground to cover, so let’s go ahead and hop into our first tool: Pandas.
In most cases, you’re probably familiar with downloading Python libraries from PyPi using a command like pip install pandas
. The good news is that pip
still does work for many Python libraries; the bad news is that it oddly doesn’t work for some other tools. Being that Pandas is one of the most prominent tools in a data scientist’s toolbox, I thought it was important to call out this alternative means of installation.
For our Pandas download to the Pi, we’re going to be making use of apt
. In case you’re unfamiliar with that is, it is a common means to install software on a Linux-based machine. (APT stands for “Advanced Package Tool.) In order to properly install Pandas on your Pi, all you need to do is run the following command in your CLI
sudo apt install python3-pandas
And that’s it! You can now use Pandas just fine. Onto our next tool!
If you’re like me and most other data scientists, chances are that you are using some form of Git to perform version control and code integration with teammates. At my day job, I use Git with GitLab, and for my personal work, I use Git with GitHub. And if you’re like me, you also likely use GitHub as a means to showcase your personal portfolio of work. That said, we’re going to both install git and “git” your Git working with your personal GitHub account. (Did you like my pun in there?)
To install git itself, apt
once again comes to our rescue. All you need to do is run the following command: sudo apt install git
. And that’s all we need to do to install Git. Before jumping into connecting our Git to our GitHub, let’s first set our git configuraiton settings. Run the following commands below to respectively set your name and email:
git config --global user.name "Your Name"
git config --global user.email "your_email@yourdomain.com"
Alright, now we’re ready to connect Git to GitHub. This is going to be a fair bit more complex than what we’ve done so far, so please be careful to follow each step in the process below. You can actually find almost all these same steps in GitHub’s official documentation, but I’ll go ahead and cover it here since the official documentation isn’t exactly linear. (There is one specific thing if you’re using the same Screens app as me.)
In the following steps, we’ll perform these three high level actions: generate a new SSH key, add the SSH key to the ssh-agent, and add the SSH key to GitHub.
Generating a New SSH Key
Since it’s been a while since I’ve done this, I honestly can’t remember if an SSH key already comes standard on your Raspberry Pi OS initialization or not. In any case, we’ll just go ahead and create a new one to make things similar on ourselves. Here are the steps to do just that:
- Open your CLI. (If you followed my steps from the last post, this will be your Blink Shell app.)
- Create a new SSH key by running the following command, substituting out your own GitHub email:
ssh-keygen -t ed25519 -C "your_email@yourdomain.com"
- When you hit “Enter”, it will ask you to “Enter a file in which to save the key”. If you enter nothing, it will go into the default location. We’re just fine with it going to the default location, so do not enter anything and go ahead and hit “Enter” again.
- Enter the passphrase you would like to use for your SSH two different times, and that will wrap up this piece!
Adding the SSH Key to the ssh-agent
With our SSH key now created, we need to add the SSH key to our ssh-agent. This is a very simple process that can be covered in two swift steps:
- Start the ssh-agent in the background with the following command:
eval "(ssh-agent -s)"
- Add your new SSH private key to the ssh-agent by running the command below. Note that if you selected the default location as recommended above, the command below will run just fine. If not, you might need to do some minor tweaking to ensure your ssh-agent is getting at the correct key.
ssh-add ~/.ssh/id_ed25519
Adding Your SSH Key to Your GitHub
We’re just about there! This is where things get a little odd since we’re using the iPad to connect to our Pi. These steps are only going to make sense if you installed the Screens app in our previous step. We unfortunately can’t just use our CLI (Blink Shell) for this last section as we’ll be using our iPad’s web browser to input these SSH credentials.
1. We’re going to use a small tool called xclip
to copy the contents of your SSH public key file to your clipboard. To install this, we’ll use our old friend apt once again: sudo apt install xclip
2. If you haven’t already, it’s now time to fire up the Screens app. The reason for this is because the xclip
tool copies the contents of the SSH key file to the clipboard of the Raspberry Pi, NOT the clipboard of the iPad itself. Fortunately, the Screens app allows us to transfer clipboard contents back and forth between the iPad and Pi.
3. Open the terminal in your Raspberry Pi interface. Just to ensure we’re on the same page, this is what I’m looking at right now:
4. Run the following command to copy your SSH key to the Raspberry Pi clipboard: xclip -selection clipboard < ~/.ssh/id_ed25519.pub
5. In order to continue using our SSH key directly on the iPad, we’ll need to transfer the contents of our Raspberry Pi clipboard to our iPad’s clipboard. This is super easy to do in Screens. In the bottom-right corner of the Screens UI, you’ll see a small square with an arrow pointing up. Click that and then click the “Get Clipboard” option. Now your SSH key will be in your iPad’s clipboard!
6. Open up your favorite browser and navigate to your personal GitHub account.
7. Navigate to your account settings by clicking on your profile photo icon in the top-right of the UI and then clicking on “Settings”
8. In the left navigation menu, click on “SSH and GPG Keys.”
9. Click the green “Add new SSH key” button.
10. You should now see the UI pictured in the screenshot below. Paste in the key from your clipboard and give the key any arbitrary name you’d like. I just have mine called “Raspberry Pi.”
11. Click the green “Add SSH Key” button, and we are done!
Congrats! You are now able to interact with your personal GitHub from your Raspberry Pi!
I personally work a lot with Docker images, so one of my biggest gripes about doing data science on the iPad by itself is that there was really no way to build or work with Docker images natively. Whereas Pythonista is an app that provides a great interface for working directly with Python, there is no special app that builds Docker images. (And yes, I understand why this is. That’s not going to stop me from being upset about it.)
Like our other tools, the Docker install on the Raspberry Pi is unconventional, but it’s fortunately not as complex as some other things. Once again giving credit where it is due, a big thank you to Sofija Simic at this website for providing these instructions.
- Ensure that we are running the latest of everything by running the following command:
sudo apt-get update && sudo apt-get upgrade
- Download the installation script from Docker’s official site by running the following command:
curl -fsSL https://get.docker.com -o get-docker.sh
- Execute the script you just downloaded:
sudo sh get-docker.sh
- Add your Pi user to the Docker group by running the following command
sudo usermod -aG docker [user_name]
(Note: If you kept the default user settings when initializing your Raspberry Pi, your username will be “pi”.)
And that’s it! if you want to ensure everything is running properly, I would run the “hello-world” container ( sudo docker run hello-world
) and see if you’re getting an output properly. We’re ready to move onto our final and perhaps most interesting tool: JupyterHub.
Chances are that you’ve used Jupyter notebooks or JupyterLab, but you might not be familiar with JupyterHub. JupyterHub takes things to the next level when it comes to creating a legitimate discovery environment. This is because JupyterHub allows multiple users, multiple compute resources, and multiple data sources to come together all under one roof. It is super nice, and we actually use JupyterHub in my day job at my Fortune 50 company.
So you might be wondering, why do we care to enable this “enterprise-grade” thing on our tiny little Raspberry Pi? I have two reasons for that, and you admittedly might not care about the one but will definitely care about the other. The one you might not care about is enabling of multiple users. But the other more important reason is that we will set up JupyterHub to instantly start right away on the Pi’s boot up, and we’ll be able to instantly connect to it from our iPad without having to initiate any special start up commands.
Once again, many thanks to Gerold Busch for providing my basis for this section. Let’s get into enabling JupyterHub on your Pi! (Note: I’m not going to cover user management in this post, but if you’re interested in that, Gerold’s post does a great job at covering that.)
We’re going to cover two overarching topics in here. The first will be enabling the auto-startup of JupyterHub on your Raspberry Pi, and the second will show you how to quickly get working with JupyterHub directly from your iPad.
Installing JupyterHub on Your Pi
1. If you haven’t already, ensure that you have all your Python configuration settings all good to go. If you’ve been following along with this series so far, you can skip to the next step. Otherwise, you’ll need to run the following commands:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo apt-get update
sudo apt-get install python3-pip
sudo pip3 install --upgrade pip
2. In order to configure a proxy that will allow JupyterHub to receive its users properly, we’ll need to install NPM (Node Package Manager) and another tool called configurable-http-proxy
. We can install these by running the following commands:
sudo apt-get install npm
sudo npm install -g configurable-http-proxy
3. We now need to install Jupyter notebooks and JupyterHub from PyPi. We can do this with one quick command:
sudo -H pip3 install notebook jupyterhub
4. JupyterHub uses a Python-based configuration file to store settings for JupyterHub. In order to make use of it properly, we’ll need to first generate it and then move it into the /root
directory. We can do that with the following commands:
jupyterhub --generate-config
sudo mv jupyterhub_config.py /root
5. We now need to edit the bind_url
in that configuration file we just created. We’re going to set it to port 8888, but it doesn’t necessarily have to be that. To do this, run the command sudo nano /root/jupyterhub_config.py
. We will then need to uncomment and update the following row with this information:
c.JupyterHub.bind_url = 'http://:8888'
6. Okay, the basic behavior of our JupyterHub start-up is now good to go. Now we just need to have our Raspberry Pi start up JupyterHub on OS bootup. To do that, we’ll first need to create a new file in systemd
. In order to start that process, run the following command: sudo nano /lib/systemd/system/jupyterhub.service.
7. Fill this new file with the following information:
[Unit]
Description=JupyterHub Service
After=multi-user.target[Service]
User=root
ExecStart=/usr/local/bin/jupyterhub --config=/root/jupyterhub_config.py
Restart=on-failure[Install]
WantedBy=multi-user.target
8. Run the following commands to put everything in order and get your JupyterHub up and running:
sudo systemctl daemon-reload
sudo systemctl start jupyterhub
sudo systemctl enable jupyterhub
sudo systemctl status jupyterhub.service
Using JupyterHub on Your iPad
If you compared my post to Gerold’s original post, you will notice that I skipped on enabling JupyterLab as the default interface for our JupyterHub instance. This isn’t because I don’t like Lab, but rather it doesn’t really work with Juno Connect, the app we’ll be using to connect to JupyterHub.
Speaking of Juno Connect, you might remember from an old post of mine my recommendation to use Juno as a Jupyter interface. Juno and Juno Connect ($9.99) are made by the same company, but the difference is that Juno is designed to work natively on the iPad whereas Juno Connect is intended only for working with remote servers. I really do like the native Juno, but it’s a tad bit limited in that you can only use pure Python libraries. (Again, another limitation of the native iPad.) Juno Connect will use the compute resources of the Raspberry Pi, so we’re not bound by those same limitations with the native Juno. They both have their use cases, so I personally have both installed.
Sorry if that last paragraph got a little bit windy. Let’s jump into setting up Juno Connect with your Pi. All you need to do is open the app and tap on “Add Jupyter Server.” If you’ve followed along with this series so far, you’ll be able to fill out the server information with these settings:
Tap “Save” and you’re good to go! If you navigate now to any of your notebooks, you’ll see the same UI you’ll be familiar with the basic Juno app. Here’s what my setup now looks like:
The coolest thing about how this works is that you aren’t limited to interacting with just Juno Connect or even your iPad. If you prefer a more native experience, you can connect to JupyterHub with your IP address directly in a regular web browser. I tested this same IP address on my iPhone — which is not at all directly connected to the Pi — and lo and behold, it works! (Although this would be a terrible way to work!)
And that wraps up this post! I’m sure there are more tools we could add, but I think this gives you more than enough to get started. I’m not sure if there will be another post in this series or not. I’m currently looking into ways into enabling a small Kubernetes cluster just for learning purposes, but I’m currently struggling to enable that. If I can get it working, I’ll write another post on that. But even if I don’t write another “Raspberry Pi + iPad” post, I’ll definitely write more data science posts. Stay tuned for those, and thanks again for reading!