Summary and Setup

Major lesson update in early 2024

The Python Intro for Libraries lesson is currently begin redeveloped. The new Python lesson will feature a different dataset (of library usage data) and will use JupyterLab (instead of Spyder). Due to the scope of changes, the lesson is being updated in a separate GitHub repository. Once the redesign is finished that lesson will replace the lesson maintained here. We will post a target date for the change here as soon as we have a clear timeline, but if you are planning to teach this lesson in early 2024 please add an issue here to let us know.

This lesson is an introduction to programming in Python for librarians with little or no previous programming experience. It uses examples that are relevant to a wide range of library use cases, and is designed to be used as a prerequisite lesson for other Python based lessons that will be developed in the future, e.g. using the Pandas for data analysis.

This lesson references the Spyder IDE, but can be taught using a regular Python interpreter as well. Please note that this lesson uses Python 3 rather than Python 2.

Under Design

This lesson is currently in its early design stage; please check the design notes to see what we have so far. Contributions are very welcome: we would be particularly grateful for exercises and for commentary on the ones already there.

Prerequisites

  1. Learners need to understand what files and directories are, what a working directory is, and how to start a Python interpreter from a terminal window.

  2. Learners must install Anaconda before the class starts.

Please see the setup instructions for details.

Installing Python Using Anaconda


Python is great for general-purpose programming and is a popular language for scientific computing as well. Installing all of the packages required for this lessons individually can be a bit difficult, however, so we recommend the all-in-one installer Anaconda.

Regardless of how you choose to install it, please make sure you install Python version 3.x (e.g., Python 3.6 version). Also, please set up your Python environment at least a day in advance of the workshop. If you encounter problems with the installation procedure, ask your workshop organizers via e-mail for assistance so you are ready to go as soon as the workshop begins.

Windows - Video tutorial

  1. Open anaconda.com/download with your web browser.

  2. Download the Python 3 installer for Windows.

  3. Double-click the executable and install Python 3 using MOST of the default settings. The only exception is to check the Make Anaconda the default Python option.

macOS - Video tutorial

  1. Open anaconda.com/download with your web browser.

  2. Download the Python 3 installer for macOS.

  3. Install Python 3 using all of the defaults for installation.

Linux

Note that the following installation steps require you to work from the shell. If you run into any difficulties, please request help before the workshop begins.

  1. Open anaconda.com/download with your web browser.

  2. Download the Python 3 installer for Linux.

  3. Install Python 3 using all of the defaults for installation.

  1. Open a terminal window.

  2. Navigate to the folder where you downloaded the installer

  3. Type

BASH

$ bash Anaconda3-

and press tab. The name of the file you just downloaded should appear.

  1. Press enter.

  2. Follow the text-only prompts. When the license agreement appears (a colon will be present at the bottom of the screen) hold the down arrow until the bottom of the text. Type yes and press enter to approve the license. Press enter again to approve the default location for the files. Type yes and press enter to prepend Anaconda to your PATH (this makes the Anaconda distribution the default Python).

Starting Python


We will teach Python using Spyder. If you installed Python using Anaconda, Spyder should already be on your system. If you did not use Anaconda, use the Python package manager pip (see the Spyder website for details.)

To start Spyder, open a terminal or Git Bash and type the command:

BASH

$ spyder

To start the Python interpreter without Spyder, open a terminal or Git Bash and type the command:

BASH

$ python3