Python Setup on Different Operating Systems (2021)

Because students bring their own laptops and devices I’ve had some trouble in the past getting everyone running python with the packages I typically use (mainly vpython). This is a quick reference about how to get up and running on Windows, OSX, and Linux.

Figure 1. Test sphere (from a Linux installation).

Linux

These should be pretty identical. Ultimately, students may want to learn how to set up virtual environments (e.g. venv), however, for our purposes python3 should already be installed.

Using a Terminal window we’ll install pip:

sudo apt install python3-pip

and use pip to install vpython (which should install numpy as a dependency).

pip3 install vpython

and finally matplotlib:

pip3 install -U matplotlib

Test the installation by running python3 and making a sphere. Run:

python3

In the interpreter enter the two lines:

from vpython import *
sphere()

A new browser tab should pop up with a sphere (Figure 1).

OSX

OSX should be very similar to the Linux installation. You may have to install the latest version of python from https://www.python.org/downloads/, but you can check to see if python3 is installed by typing into a Terminal window:

python3

which will start the interpreter if python3 is installed.

Windows

Download and install the latest version of python (3.9 at the moment) from https://www.python.org/downloads/ . I then followed the instructions on Installing Packages for Windows.

The following commands will be run using the Command Prompt application:

First check that python is installed (and which version it is):

py --version

which should show something like (if it does not then something probably went wrong with the installation):

Python 3.9.7

Now install and upgrade pip (and setuptools and wheel):

py -m pip install --upgrade pip setuptools wheel

Install vpython (which includes numpy)

py -m pip install vpython

And matplotlib:

py -m pip install matplotlib

Test by opening the IDLE App, and at the interpreter prompt typing the two lines:

from vpython import *
sphere()

and you should see Figure 1 pop up in a new browser tab.

LED Light Strip with Pi Zero

Raspberry Pi Zero controlling a LED strip, with a hardwired clear button.

I wanted to set up a small (20 LEDs) light strip using a Raspberry Pi Zero, so students could learn how to remotely log in to a device, work with the Linux command line, run python programs, and get visible, real feedback on their progress.

Instructions and code are in the Github rpi-led-strip repository.

Web control for the LED strip.

The repository also has instructions and code for setting up a local server on the Pi so you can control the LED strip via a webpage. Students working on their own LED projects in the Makerspace will appreciate this.

The main idea here was to make the project as simple as possible. The web page is basic with minimal styling, so it should be easy to edit, but I do test out some of the newer HTML input elements, like the color picker. The README in the repository also includes instructions on how to, step by step, add components to the webpage to control the Pi: the “Blue” button is used as the example (it sets the entire strip to blue).

With only 20 LEDs you don’t need an external power supply so everything can be run through the Pi.

Adafruit’s CircuitPython NeoPixel library makes controlling the lights really easy. There are a few example programs in the rpi-led-strip/pyLED/ directory of the repository.

The full strip.

I’ve also included a physical button (it’s optional) that I’m using right now to just clear the LED strip. I may change it to just reboot the Pi, because I anticipate that things will get interesting when I have an entire class trying to connect to one or two devices. So far, I’ve had a small group of four students try this with some success.

Linux Laptops

We had a couple laptops recently donated to the Makerspace (thanks Ms. A) and I’ve installed Ubuntu’s Linux (20.04 LTS) to see if I could get them to be useful for my students. I particularly wanted to see how hard they’d be to set up for programming (especially given the issues I’ve had with python). They’re working quite well so far, and this is my record of what I’ve done to set them up.

Installing Ubuntu

Ubuntu makes it really easy to install their operating system; it’s the main reason it’s one of the more popular flavors of Linux. You can download the ISO and get instructions on how to create a USB installation stick on their page.

Getting System Information

inix is a nice tool to for finding information about your computer (which you sort-of need when you’re dealing with donated machines): what type of cpu, how much RAM, size of the hard drive and things like that. Install with:

sudo apt-get install inxi

and to get the full set of information, run:

inxi -F

Extremely useful, but I did not really need this to tell me that I needed to upgrade the hard drive. Swapping the hard disk drive (HDD) for a solid state drive (SSD) is one of the quickest and cheapest ways to upgrade an older system. I picked up a 120 Gb SSD for less than $20 and the computer is now an order of magnitude faster (though I’m down from 500 Gb).

Upgrading

The final step after installing the operating system is to update the software. Ubuntu runs an automatic update on your first boot. However, since I’ll be doing most of my installations from the command line, I run the update commands (just in case):

sudo apt update
sudo apt upgrade

Setting up Python

Python 3.8.5 was installed by default, but I need the python package installer (pip) to install the modules I’ll need:

sudo apt install python3-pip

Now I can install numpy (-U option to upgrade) for numerical stuff:

pip3 install -U numpy

as well as, matplotlib:

pip3 install -U matplotlib

and vpython

pip3 install vpython

and for virtual environments (venv):

pip3 install virtualenv

and the IDLE editor for python

sudo apt-get install idle3

also the Thonny editor that makes using Raspberry Pi Picos much easier (especially for the pico LED strips)

sudo apt install thonny

Now we should be good to go.

git, github, and vs code

git: I’ve been using github.com for keeping my programming projects and GitHub Classroom for my programming class. The GitHub Desktop program is great for Windows and OSX, but does not exist for linux at the moment. So I needed to install git:

sudo apt install git-all

VS Code is a pretty popular IDE for coding that I’ve been using for my computer programming class. It’s a Microsoft product that is designed to work closely with github repositories. You can download the .deb from

It’s usually saved in the ~/Downloads folder, so to install this should work:

sudo apt install ./Downloads/code*.deb

I usually test the VS Code installation with my ledPixelsPico repository because I want to make sure I can operate my Raspberry Pi Pico LED strips.

To get VS Code to be able to make commits and sync with the repository (you’ll have to test this with a repository of your own–or that you have permission to sync with) you’ll need to run the ‘git config –global user.email “you@example.com”‘ and ‘git config –global user.name “Your Name”‘ commands in the VS Code Terminal.

LaTeX

For typesetting beautiful documents (mainly for the equations) I use LaTeX.

Since I don’t want to worry about downloading LaTeX packages when I need something esoteric I install the full Tex Live distribution (Note: for texlive on Fedora use ‘texlive-scheme-full‘).

sudo apt-get install texlive-full

Editor: To use LaTeX we need an editor. I prefer TeXstudio:

sudo apt-get install texstudio
  • Folder with all files needed to test the typical things I do with LaTeX in a chapter format: LaTeX Demo Report.

NOTE: if you’re low on memory, you can install something like Miktex instead of Tex Live because it installs packages only when you need them. Also, some of my students who use Apple computers seem to find TexShop easier to set up than TexStudio.

Installing Additional Software

The basic Ubuntu installation comes with a lot of the free software I use, but, using the command line:

sudo apt install ...

or the Ubuntu (or other package manager) Software tool, I added:

  • [Atom] [depreciated]: text editor for coding (being depreciated unfortunately, I’ve been forced to use VS Code instead: see above, or Thonny: see below and above).
  • Thonny: Coding editor for working with Raspberry Pi Picos in particular (may already be installed from the python section above).
  • GIMP: for image editing
  • Inkscape: for vector graphics
  • OpenScad: for 3d Modeling (for printing)
  • Shotcut: for video editing (it’s multi-platform). I’m trying this one for extracting time information from experiments (like ball drops). Can install with ‘sudo apt-get install shotcut’

UxPlay [Optional]: A crucial piece of software for online teaching that I had to install via the command line was, UxPlay, and you can see my variant of the installation instructions here. This program allows me to mirror my iPad to the computer.

The Rest

The rest is mostly tweaking the settings to your specifications (there’s even a program called Tweak you can install for extra settings).

Tweaks

I use this to enable hot-corners and customize the desktop interface.

sudo apt install gnome-tweak-tool
sudo apt install gnome-shell-extensions
Fonts

Added the student fonts following LinuxConfig’s instructions, specifically the section on “Manual system-wide font installation”, which just meant copying the folder with all the fonts to the “/usr/local/share/fonts/” directory.

php

I use php a lot so I’ve set it up so I can run php off the command line (I haven’t figured out how to use url parameters this way though).

sudo apt install php libapache2-mod-php
sudo apt install php-cli
gdebi

gdebi is a little application for installing .deb software. I’ve had enough hiccups with the Ubuntu Software tool, to find it useful to right click a downloaded .deb file and install it using gdebi. To install:

sudo apt install gdebi
Imager

The first thing I used gdebi to install was Imager, which is used to write the Raspberry Pi operating system to USB’s or SD cards. Download the imager .deb, right click and install using gdebi.

nmap

nmap maps your local network, which is useful if you have a bunch of Raspberry Pi’s around and need to figure out their IP addresses.

sudo apt-get install nmap

To use nmap to find all the raspberry pi’s on the local network use something like this, where you change the IP address (192.168.4.0) to whichever IP your computer is on, but switch the last number for 0:

sudo nmap -sP 192.168.4.0/24 | grep -in -B 2 'pi'