yeti logo icon
Close Icon
contact us
Yeti postage stamp
We'll reply within 24 hours.
Thank you! Your message has been received!
A yeti hand giving a thumb's up
Oops! Something went wrong while submitting the form.

Set Up a Raspberry Pi with Raspbian, running Python 3.5

By
-
April 7, 2017

The Python Foundation has really been amping up the real-time capabilities of Python with the new asyncio library. Asyncio enables Pythonistas to write code that is asynchronous, allowing for a more event-driven approach to writing software.

What platform would benefit more from this new tech than microcomputers like the Raspberry Pi, which are finding new life as lightweight, yet powerful IoT (Internet of Things) devices? In my never-ending quest to set up a feedback system in my office where light levels can be communicated to an automated shade setup, I figured this would be the very first step to get there.

Goal

I wanted to have a Raspberry Pi that checks the following boxes:

Materials

Install Raspbian onto SD-Card for Pi

Raspbian is the go-to OS for Raspberry Pi. It has the most support on this hardware, and also runs the smoothest. It is a Linux Distro that is Debian-based, so a lot of the software packages you can install in Debian and Ubuntu are the same as the ones you can install on Raspbian.

PiBakery Route (Recommended)

  1. Install PiBakery
  2. Use the handy-dandy interface to do the following:
  3. On First Boot:
  4. Set hostname to <hostname>.local
  5. Set user password to <password>
  6. Setup Wifi (with Network, Pass and Type, also Type should be WPA/WPA2)
  7. Reboot

NOOBS Route

  1. Go to the Raspberry Pi Software Setup Page
  2. Follow their instructions to do the following:
  3. Install Raspbian
  4. Setup Wi-Fi
  5. Setup the Pi's hostname

Setup The Python Environment

Using a Python version manager like pyenv to install Python makes the process less a painful chore and more a pleasant pastime. Raspbian comes with Python 2.x and the package manager enables installing Python 3.4.x, but if we want to mess around with asyncio's fabulous async/await syntactic sugar, Python ≥3.5 is where it's at.

  1. Plug SD Card into Pi and plug in the power.

  2. If you went the NOOBs route, you'll want to set hostname on your Pi so that you don't have to look for the IP every time.

  3. Wire Pi up to monitor and keyboard and then open the terminal OR ssh to it (ie ssh pi@<hostname>.local then enter <password> at the prompt).

  4. Once you're logged in, install a bunch of other much-needed but under-appreciated dependencies with the following:sudo apt-get update && sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev openssl bzip2
  5. Run pyenv-installer with the following command:curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  6. Copy the following lines into the ~/.bashrc file or into any file that you'll have ~/.bashrc execute.export PATH="~/.pyenv/bin:$PATH"
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
  7. Run ~/.bashrc with source ~/.bashrc or . ~/.bashrc
  8. Run pyenv install 3.5.1. Pyenv should now be installing Python 3.5.1 into ~/.pyenv/bin. This will take anywhere between 10 minutes to an hour, depending on your internet connection and whether you went with a Pi 3 or a Pi Zero W.
  9. Run pyenv global 3.5.1. The global Python version your Pi will use is now 3.5.1.

And that's it! Optionally, you can install something like virtualenvwrapper, but on lightweight platforms like the Pi, I tend to just install things directly, since it's unlikely I'll be using it for anything else.

Why Python 3.5?

At this point, you might be asking me, "Dean, why did you make me go through pyenv-installer to install Python 3.5 when Python 3.4 also has asyncio, albeit in a slightly diminished form?". Let me refer you to this page, which details all the ways in which asyncio is made even better with the availability of things like asynchronous context managers (because calling anything.close() directly is such a drag), async/await syntax, and other new goodness. Also, with PEP448, unpacking from lists and dicts is even better! Who wouldn't want that!

You Might also like...

colorful swirlsAn Introduction to Neural Networks

Join James McNamara in this insightful talk as he navigates the intricate world of neural networks, deep learning, and artificial intelligence. From the evolution of architectures like CNNs and RNNs to groundbreaking techniques like word embeddings and transformers, discover the transformative impact of AI in image recognition, natural language processing, and even coding assistance.

A keyboardThe Symbolicon: My Journey to an Ineffective 10-key Keyboard

Join developer Jonny in exploring the Symbolicon, a unique 10-key custom keyboard inspired by the Braille alphabet. Delve into the conceptualization, ideas, and the hands-on process of building this unique keyboard!

Cross-Domain Product Analytics with PostHog

Insightful product analytics can provide a treasure trove of valuable user information. Unfortunately, there are also a large number of roadblocks to obtaining accurate user data. In this article we explore PostHog and how it can help you improve your cross-domain user analytics.

Browse all Blog Articles

Ready for your new product adventure?

Let's Get Started