© JR 2021

Python on RISC OS



Purpose and scope

If you are reading this then obviously you have some interest in Python but perhaps need to be convinced that it is worth the considerable effort to learn a new language. After all, RISC OS comes with its own mature and capable builtin programming language. BASIC is well documented and has tried and tested development tools to go with it.

There are good arguments for learning Python but to keep this introduction short I have put the reason at the end in the the Zen section.

This guide is for people who wish to use Python on RISC OS but are unsure of how to start.

The Pythonic Universe is immense and indifferent. If you are use one of the big three OS's you will find that most things work. But for inhabitants of minor planets like RISC OS the Python that is "out there" is a minefield. This Documentattion is written to guide people through it.

It won't go into detail on Python syntax or how to use Python to solve problems. There are resources online which covers this ground exaustively and if you prefer the written word, there are books for beginners, intermediates, and experts and supplied with Python itself there is a comprehensive set of reference material.

What is really useful are the YouTube videos which cover all aspects of the language for beginners, intermediates and experts alike.

This guide covers how to set up an environment for developing and using Python applications under RISC OS. It also describes and explores some of the many external resources in the Python world and warns of functions that do not work on RISC OS.

Installing Python

If you have experimented with Python in the past, there may be stuff in your computer which will cause grief. A good way to start afresh is to remove as much of it as you can find.

You can issue a *show *pyt* in a command window to see if there are any Python paths or aliases set.

If you have installed an early version of Python using PackMan you can ask it to uninstall anything Python related. Good luck!

When you believe you have a clean system you can begin by using PackMan to install Python-38, this is where a current stable version of Python is available for RISC OS. If you don't get on with package managers and are capable of installing Python and its dependencies manually then you probably don't need this guide.

So, now you have installed Python, but perhaps would like to know what else has been added to your system and where Packman has put it ?

The RISC OS Python release has three components packaged as RISC OS applications. Unless you changed the default locations, PackMan will have installed them here:-

 .... $.Apps.Development.!Python3
 .... $.!BOOT.Resources.!PythonSite
 .... $.!BOOT.Choices.Boot.PreDesk.!PythonUser
In addition to its own components Python has some dependencies. You may have some of these installed already as they are used by other Unix ported software. For example !SharedLibs. Python will install any that are missing and may try to update any that exist but are older than the one Python requires. It could get a bit messy. Here is what PackMan reports after installing Python38.

Testing the Install

Open the directory "..$.Apps.Development" and double click on !Python3.

This will open a TaskWindow using your current editor. It should look like this:

Type "hello world" at the >>> prompt and press return.

The python interpreter parses the input, acknowledges it as valid, and writes it back to the screen on a new line (without a prompt) as: 'hello world' - note the single quotes

The interpreter then writes the >>> prompt on a new line and waits for further input.

For what it is worth, Python beats all-comers in the challenge to put "hello world" on a screen in the minimal number of keystrokes.

Now type "quit()" to leave the python interpreter and return to a standard "*" prompt task window.

You can restart the python environment now by typing "python3" at the star prompt and exploring it.

If you have got this far then you have a working installation of Python3. It is fun to explore python using the shell, and it makes an excellent calculator. Just type a numerical expression and python will evaluate, reduce it to a single value and print it out.

However, for repeatable results we need to save the instructions in a file and run them. The major operationg systems, Apple, Linux, Windows, have a wide choice of Integrated Development Enviroment tools (IDEs) for creating and managing python coding. RISC OS does not. Python has its own Integrated Development and Learning Environment named IDLE. I Presume it is a salute to Eric. This is its icon:

I have made various attempt to cobble together an IDE of sorts from existing RISC OS components. These are described in a later section of this document.

Making a Home for Python

If you have followed the advice given above you have a working Python interpreter installed in ..$.Apps.Development. I am now going strongly to recommend that you copy it to somewhere else on your hard disk, to a location where you can keep all of your python work, tutorials and trials together and be secure in the knowledge that is safe from changes and updates to the os system and that all the content is under your control.

On my machine I created a directory in the root of the hard drive, as I wanted a short path length, and named it PYTHON. The caps may be over the top for some tastes.

There is more on this user location in the section on IDE.

© 2021 JR