How to use Environment Variables to Configure GPIOZero in Python3 Mode

Some libraries (such as GPIOZero) look up configuration information in user-defined settings called environment variables. Mu allows you to define what these environment variables should be so that whenever you run a script or use the REPL in Python 3 mode, these settings are available to your code.

If you look at the documentation for the GPIOZero library, you’ll see that you probably need to set the following environment variables for it to work properly:


The steps to make this happen in Mu are very simple:

Click on the “cog” icon in the bottom right hand corner of Mu’s window (highlighted in red in the image below). This will open up the “Mu Administration” dialog.

The cog button

Select the “Python 3 Environment” tab and fill in the environment variables as shown below. Each environment variable must be on its own line and of the form NAME=VALUE.

Environment variables

Attention! The settings shown above are examples

The correct value of the PGPIO_ADDR environment variable for your system will be different from the example shown above (highlighted in blue). Please consult the documentation for GPIOZero for more information.

Environment variables are saved and will remain in place when you re-start Mu. If you want to delete an environment variable, simply remove it from the text area shown above!