Here's a set of Ansible playbook files to do an unattended compile of Python 3.7+ with SSL on a
headless wifi-connected Raspberry Pi. A recent project of mine (bricknil) uses 3.7, and
it was a little frustrating to get the default 3.5 upgraded on my Raspbian image --
I had to compile Python from source with the newer SSL libraries (so that pip works), and get around some uuid
compilation issues that took a fair bit of web research to figure out.
Everything is run from the local machine
talking to the Pi over ssh, and you just need Ansible installed on your local machine (which can be
as easy as pip install ansible depending on your OS). Hope this helps save some time for anyone else needing
get modern Python installed on their RPi!
Now, you should be able to use this SD card to boot your raspberry pi. After giving it a few minutes to boot, you can login in by doing the following on your local machine:
ssh pi@raspberrypi.local
<enter 'raspberry' as the default password>
You may need to modify the hosts file in pi_setup directory to put in your own IP address for the Pi.
You will need to install the python library passlib by running pip install passlib on your local machine (not the Pi). This is needed to hash the new password.
Use the change_password.yml playbook to test your ansible install and change the default password on the pi (use raspberry for the ssh password when prompted, and then enter your new password):
The final step is to just run the the install playbook. This will install all the packages, download and compile OpenSSL, followed by Python 3.7, and set up
a virtualenv. The actual playbook is in tasks.yml, shown below and included in the source, and the command to
execute it on your local machine is:
ansible-playbook -i hosts tasks.yml --ask-pass
The install will take around two hours, so please be patient. Most of the time is spent compiling and installing Python from source. Here's the playbook being executed:
At the end, there are a couple of steps where I install a sample package and clone a github repo (which in
this case is my bricknil project for controlling Lego trains and robots. Python 3.7 will be available as
/usr/local/bin/python3.7 and virtualenvwrapper will use it as the default python.
And that's it! Your raspberry pi should be ready to go as a networked appliance with an up-to-date Python.