© JR 2021

Python on RISC OS


Introduction


Top

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 cover 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 as follows and added them to the in Configuration-Boot "Look at" list.

 .... $.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, evaluates the expression, and writes the result 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.

Sadly this is not true, Windows Powershell wins here. On a windows machine start Powershell and type "hello world" and it comes back as: hello world, no quotes.
On RISC OS ctrl-12 python "hello world" (20 keysrokes)
On Windows winkey-r wt "hello world" (16 keystrokes)
This sketch is getting silly, but by setting a short alias for python
Set alias$p python
you can get RISC OS down to 15 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. Progress so far is described in the Work in Progress 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. It is useful to have somewhere else on your hard disk, where you can keep all your python related files, programs, tutorials and tests together; where all the content is under your control and you are secure in the knowledge that is safe from changes and updates to the os system.

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.

© 2021 JR