Lecture 0: The Ecosystem

Yes, we're zero indexing!


Git is a version control system that runs on your computer. You can commit changes to the repository and it will save a history of these commits, allowing you to reference them or go back to them at any time. GitHub is a hosting service that essentially backs up your Git repositories (when you push to them or pull from them) so that you can acccess them from anywhere and there is a reduced chance of data loss. You can also check out other people's GitHub repository by clone-ing them.


There are basically two ways to intall Python. One is the "native" way using whatever facilities exist with your operating system (for OSX this would be homebrew), and then using pip to install packages. The other way, which is generally more user-friendly and OSX/Windows friendly is to use the Anaconda distribtuion and conda to install packages.

The most bare-bones way to run Python is to just execute python in the terminal. Depending on your setup, this might actually run Python 2, which is quite old at this point, so it's often safer to run python3 explicitly. Anyway, you'll almost never need to do this. At the very least you'll want to run in a more user friendly environment like IPython by executing ipython3, which is sort of a wrapper around python3.

But even then, most of you will prefer to use Jupyterlab. This is a web-based graphical interface that is primary centered on "notebooks", which is what you're looking at now basically. It's just a series of cell (code or markdown) that when run produce some kind of output. Notebooks are a way to store the code you've written and the resulting output in one place.

The other place where Python code might "live" is in Python files, which are just text files with the extension .py. If you have a file named model.py, you can run its contents directly with python3 model.py. If you're in an IPython terminal and you want to run its contents interactively, you can run run -i model.py. Finally, you can use it as a module. In this case you can run the Python command import model and there will be a new variable model that contains any variables defined therein. So if you'd defined abc = 5 in model.py then model.abc will be 5.


Nowadays, you can do almost everything in Jupyterlab. That can be useful, especially if you're working on a remote machine like the Pitt cluster. However, I must emphasize that you shouldn't be doing everything in notebooks. For suffiently complex code, you'll want to put some portions of it proper Python modules (.py files, basically) and import them for usage in a notebook. Thus your notebook will contain mostly high level commands and their resulting outputs.

You can create a new notebook (.ipynb file) by clicking on the blue "+" on the left and chooseing a Python version (something like 3.9 or higher is recommended). You can also create other file types like Python (.py) or markdown (.md) or open a system terminal. Finally, you can edit any of these files by double clicking on them in the filesystem pane on the left.


You'll want to stick mostly to the keyboard. To run a cell, press Shift+Enter. To run a bunch of cells in a row, just hold down Shift and keep pressing Enter. To enter edit mode on the selected cell, press Enter. To exit edit mode on a cell, just press Esc. To interrupt ongoing execution, press i twice. To completely restart a notebook press0 twice. Create new cells above or below with a and b.

You can make a cell into a markdown cell by pressing m. Press y to turn it back into a code cell. In markdown mode, you can make headings with one or more #s, amongst other markdown features such as pairs of ** for bold text. You can also do inline $\LaTeX$-style math with pairs of $, as in $x^2$, or display style math with pairs of $$, as in $$ \int_{-\infty}^{\infty} \exp(-x^2) dx = \sqrt{\pi} $$