How to setup Raspbian Stretch Lite on Raspberry Pi 3 to run Python 3 applications

Raspbian Stretch Lite operating system is the Raspberry Pi Foundation's official supported operating system for running headless software. It is a good operating system for different Raspberry Pi 3 use cases. Some examples include:

If you are planning to use Raspberry Pi 3 GPIO to interface with the real world, it is recommended that you setup Raspbian Stretch Lite to run Python 3 applications.

This post provides the steps to setup Raspbian Stretch Lite on Raspberry Pi 3 for running Python 3 applications.

Recommended hardware list

Setting up Raspbian Stretch Lite with SSH server enabled on your microSD card

Once you had gathered all the necessary hardware, proceed to setup Raspbian Stretch Lite with SSH server enabled on your microSD card. Doing so will allow you to SSH into your Raspbian Stretch Lite to perform further configurations in this post.

Assembling the hardware for the Raspberry Pi 3

Once the ssh file is created in the boot partition of the microSD card, remove the microSD card from your SD card reader and insert it to the microSD card slot on the Raspberry Pi 3 board. After that, proceed to assemble the Raspberry Pi 3 board to the Official Raspberry Pi case.

Starting the Raspbian Stretch Lite operating system

With the assembly of your Raspberry Pi 3 board and Official Raspberry Pi case, connect one end of the RJ45 cable to the RJ45 port on the Raspberry Pi 3 board and the other end of the cable to one of the switch port of your home router. After that, connect the micro USB power supply to the Raspberry Pi 3 board and a wall socket. Turn on the power socket to supply power to the Raspberry Pi 3 board.

Changing default password, Locale and Timezone of your Raspbian Stretch Lite

There are a few configurations that you should perform on the first run of your Raspbian Stretch Lite. Proceed on to change the default password, Locale and Timezone of your Raspbian Stretch Lite.

Checking if Python 3 is included in Raspbian Stretch Lite by default

Raspbian Stretch Lite includes Python 3 by default. We can verify that by running the following command:

dpkg --get-selections | grep python3

which returns the following output:

libpython3-stdlib:armhf				install
libpython3.5:armhf				install
libpython3.5-minimal:armhf			install
libpython3.5-stdlib:armhf			install
python3						install
python3-apt					install
python3-minimal					install
python3.5					install
python3.5-minimal				install

Installing Python 3 package manager (pip3) on Raspbian Stretch Lite

This version of Raspbian Stretch Lite did not install the Python 3 Package Manager by default. The Python 3 package manager will be useful for managing the dependencies for your Python 3 applications. As such, proceed to install the Python 3 Package Manager on Raspberry Stretch Lite.

To install the Python 3 Package Manager, run the following command:

sudo apt-get install python3-pip -y

Once the Python 3 package manager is successfully installed, you can run the following command to see the Python 3 Packages that are available in the system:

pip3 list

Running the command can show output similar to the following:

cryptography (1.7.1)
idna (2.2)
keyring (10.1)
keyrings.alt (1.3)
pip (9.0.1)
pyasn1 (0.1.9)
pycrypto (2.6.1)
pygobject (3.22.0)
python-apt (1.1.0b5)
pyxdg (0.25)
SecretStorage (2.3.1)
setuptools (33.1.1)
six (1.10.0)
wheel (0.29.0)

Installing Virtualenv on Raspbian Stretch Lite

Virtualenv is a tool that allows us to create isolated environments in the same machine. This is useful if you have to run multiple applications with conflicting python dependencies on your Raspberry Pi 3.

To install Virtualenv, I run the following command:

sudo apt-get install virtualenv -y

Buying your Raspberry Pi 3 components from Amazon

If you do not have the Raspberry Pi 3 components mentioned in this post yet, you may want to purchase them from Amazon. Simply click on the button below to add the Raspberry Pi 3 components to your cart. You may remove anything that you already have or replace some of the components with other components.


About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.