Installing Python 3.7.2 on a Raspberry Pi/Raspbian

Alexander Rüedlinger - - Python , Python 3.7.2 , asyncio , Raspberry Pi , Raspbian , Stretch

Unfortunately, the Python 3 version on Raspbian/Stretch is stuck at Python 3.5.3, which means we can't take advantage of the recent changes of the awesome asyncio api. However, we can build and install the latest version from source on the Raspberry Pi as shown below:

tar xfv Python-3.7.2.tgz
cd Python-3.7.2
make -j4
make altinstall 

To test the new Python version, we can run, for example, an asyncio based program like the one shown below:

#!/usr/bin/env python3.7
import asyncio
import time

async def say_after(delay, what):
    await asyncio.sleep(delay)

async def main():
    print(f"started at {time.strftime('%X')}")

    await say_after(1, 'hello')
    await say_after(2, 'world')

    print(f"finished at {time.strftime('%X')}")

If everything went fine, then we should see a hello world output :D.