Link Search Menu Expand Document

Running Python

Running the course Notebooks

Once the course git repository has been cloned locally you can run the course notebooks and follow along in class or try them at home.

First, change the directory to the data-focused-python directory of your clonned repository,.

cd data-focused-python

Then start Jupyter from your terminal

jupyter-lab

What is Jupyter?

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. If you’ve installed Anaconda, Jupyter is packaged as part of the distribution.

I encourage you to review the more detailed How To Use Jupyter Notebook – An Ultimate Guide.

Running the Python Interpreter

Python itself is an interpreted programming language which means the source code you type gets executed by the interpreter at runtime. You can start the python interpreter from any command line by executing the following in your terminal:

python

I encourage you to try it out. You can follow along the official python docs here

Running the IPython Interpreter

IPython builds on the Python interpreter adding advanced read-eval-print-loop (REPL) functionality among other features.

You can start the ipython interpreter by executing the following command in your terminal:

ipython
# in anaconda
## find the location of your virtual environment
!which python
/Users/bk/opt/miniconda3/envs/cmu39/bin/python
## run IDLE out of that location
!/Users/bk/opt/miniconda3/envs/cmu39/bin/idle3.9 &

Executing Python Files

Using the Python interpreter is great for small problems, testing libraries, etc. but all of your code lives in memory inside the python interpreter. When the interpreter stops your code is gone forever. In order to get around this limitation you can create python script files and execute the files using the interpreter.

Create a file on your harddrive called hello.py. Copy and paste this code into the file and save it.

print('Hello class')
print('Welcome to 95-888')

You can then execute the file by typing this command into your terminal.

python hello.py
!python hello.py