Installing Python RPi Libraries in Arch Linux

With Arch Linux installed on my Raspberry Pi Zero it was time to figure out how to install the RPi libraries for Python. All other Raspberry Pi distros (like Raspbian) come with those libraries pre-installed. But since I wanted to use Arch Linux, manually installing the RPi libraries is part of the fun (or experiment in my case).

Luckily, the RPi.GPIO library is available in PyPI (Python Package Index). PyPI is Python's shareable code repo. Installing packages from PyPI requires pip. Luckily, both Python and pip are available in Arch Linux ARM and can be installed with pacman. After trying to install RPI.GPIO via pip the first time and failing, I realized you need to install GCC as well. So here are the two commands you need to run to install Python and the RPi.GPIO libraries.

As root, run:

pacman -S python python-pip gcc
pip install RPi.GPIO

That's it! It's that easy.

Please note that the above commands install Python 3 (version 3.5 at the time of writing). (If you are still living in the past and want Python 2 you may be able to use it. I won't be using Python 2 if I can avoid it. If you don't know which version to use, use Python 3.)

At that point you can do a basic test of the libraries to make sure things are working OK (also as root):

# python
Python 3.5.1 (default, Mar  6 2016, 12:32:57) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(21, GPIO.OUT)
>>> GPIO.output(21, GPIO.HIGH)<br>>>> # Pause right here and check GPIO pin 21 is high (3.3 V)
>>> GPIO.output(21, GPIO.LOW)
>>> GPIO.cleanup()
>>> quit()

Between the output calls that set the pin HIGH and LOW, GPIO pin #21 (physical pin 40) should go high (3.3 V). Since I don't have the pin headers soldered yet, I checked the output with a regular multimeter. The easiest way to check the pin voltage was to put the probe leads on the last (bottom) two pin holes (the two farthest away from the MicroSD card). If you wish to test another pin, simply replace the number 21 in the calls with another GPIO pin number. Here is the pinout of the Raspberry Pi Zero with physical pin numbers (1-40) and BCM pin names (thanks rasp.io for the image of their card):

Image description I have to admit, however, that I was surprised to see the voltage on the pin was 3.3 V. I really expected it to be 5 V since I was feeding the Pi Zero 5 V through the USB port. Good to know!

In conclusion, yes it is possible to program the Raspberry Pi with Arch Linux and Python. Installation of the RPi.GPIO libraries was incredibly easy thanks to PyPI and pip and they work.