blog.lexruee.ch
Yet another blog on the Web.

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:

wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar xfv Python-3.7.2.tgz
cd Python-3.7.2
./configure
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)
        print(what)

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')}")

asyncio.run(main())

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

© Alexander Rüedlinger, 2017-2019
Proudly powered by Pelican, which takes great advantage of Python.