Skip to Content

Department of Mathematics

Python Setup Guide

Introduction

This guide will help you set up your personal computer to work on the calculus lab assignments at home. The labs use Python and Jupyter Notebooks, which are powerful tools for mathematical computation and visualization. We will be using Visual Studio Code (VSCode) as our code editor because it provides an excellent integrated environment for working with Python and Jupyter Notebooks.

By the end of this guide, you will have:

  • Installed Python 3 (latest version)
  • Installed necessary Python packages (NumPy, SymPy, Matplotlib, iPyWidgets)
  • Installed and configured VSCode
  • Set up Jupyter Notebook integration in VSCode
  • Verified your installation with a simple test

System Requirements

This setup should work on any relatively modern computer running:

  • Windows 10 or 11
  • macOS 10.15 or later
  • Linux (Ubuntu 20.04+, Fedora 34+, etc.)

Minimum hardware requirements:

  • 4GB of RAM (8GB recommended)
  • 5GB of free disk space
  • Internet connection for downloading software and packages

Installing Python

Python is the programming language we’ll be using for our calculus labs. We need Python 3.9 or newer.

Windows

  1. Visit the official Python website: python.org/downloads
  2. Download the latest Python 3 installer. The 64-bit version is recommended.
  3. Run the installer.
  4. Important: Check the box that says Add python.exe to PATH before clicking Install.
  5. Click Install Now to begin the installation with default settings.
  6. After installation completes, open Command Prompt and verify the installation by typing:
python --version

You should see the Python version number displayed.

macOS

  1. Visit the official Python website: python.org/downloads
  2. Download the latest Python 3 installer for macOS.
  3. Run the installer package and follow the installation instructions.
  4. After installation, open Terminal and verify by typing:
python3 --version

You should see the Python version number displayed.

Linux

Most Linux distributions come with Python pre-installed, but it may be an older version. To verify, open Terminal and type:

python3 --version

If Python is not installed or you need to update, use your distribution’s package manager:

Ubuntu/Debian

sudo apt update
sudo apt install python3 python3-pip

Fedora

sudo dnf install python3 python3-pip

Installing Required Python Packages

For our calculus labs, we need several specialized Python packages. We’ll use pip, Python’s package installer, to install them.

Required Packages

  • NumPy: For numerical computations
  • SymPy: For symbolic mathematics
  • Matplotlib: For plotting and visualization
  • iPyWidgets: For interactive features
  • Jupyter: For working with Jupyter Notebooks

Installing Packages

Open Command Prompt (Windows) or Terminal (macOS/Linux) and run the following command:

Windows

pip install numpy sympy matplotlib ipywidgets jupyter

macOS / Linux

pip3 install numpy sympy matplotlib ipywidgets jupyter

If you encounter permission errors on macOS or Linux, you may need to use:

pip3 install --user numpy sympy matplotlib ipywidgets jupyter

Installing Visual Studio Code (VSCode)

VSCode is a lightweight but powerful code editor that we’ll use to work with our Python files and Jupyter Notebooks.

Download and Install VSCode

  1. Visit the VSCode download page: code.visualstudio.com/download
  2. Download the installer for your operating system.
  3. Run the installer and follow the prompts.
  4. For Windows users, ensure the following options are selected:
  • Register Code as an editor for supported file types
  • Add to PATH (requires shell restart)

Setting Up VSCode for Python and Jupyter Notebooks

After installing VSCode, we need to configure it for Python development and Jupyter Notebooks.

Installing Python and Jupyter Extensions

  1. Open VSCode.
  2. Click on the Extensions icon in the sidebar, or press Ctrl+Shift+X on Windows/Linux or Cmd+Shift+X on macOS.
  3. Search for and install the following extensions:
  • Python (by Microsoft)
  • Jupyter (by Microsoft)
  1. After installation, restart VSCode to activate the extensions.

Configuring Python Interpreter in VSCode

  1. Open VSCode.
  2. Press Ctrl+Shift+P on Windows/Linux or Cmd+Shift+P on macOS to open the Command Palette.
  3. Type Python: Select Interpreter and select it.
  4. Choose the Python installation you installed earlier.

Verifying Your Installation

Let’s create a simple test notebook to ensure everything is working properly.

Create a Test Notebook

  1. In VSCode, go to File → New File.
  2. Select Jupyter Notebook.
  3. Save the notebook with a .ipynb extension.
  4. Add the following code to a cell:
import numpy as np
import sympy as sp
import matplotlib.pyplot as plt

# Define a symbol for mathematical operations
x = sp.Symbol('x')

# Print a simple calculation
print("NumPy calculation:", np.sqrt(16))

# Show a symbolic math operation
expr = sp.sqrt(x**2 + 1)
display(expr)

# Create a simple plot
t = np.linspace(-np.pi, np.pi, 100)
plt.plot(t, np.sin(t))
plt.title("Sine Function")
plt.grid(True)
plt.show()
  1. In the top right, click Select Kernel.
  2. Select Python Environments... from the drop-down menu, if necessary.
  3. Select the version of Python you installed earlier.
  4. Run the cell using Shift+Enter.

Expected Output

After running the cell, you should see:

  • A text output showing NumPy calculation: 4.0
  • A nicely formatted mathematical expression for sqrt(x^2 + 1)
  • A plot of the sine function

If all of these appear correctly, congratulations. Your setup is complete and working properly.

Working with Jupyter Notebooks in VSCode

Opening Existing Notebooks

  1. In VSCode, go to File → Open Folder and select the folder containing your lab files.
  2. In the Explorer sidebar, find and click on any .ipynb file to open it.
  3. VSCode will load the notebook with a Jupyter interface similar to what you’ve seen in the lab.

Working with Notebook Cells

  • Click the + Code button to add a new code cell.
  • Click the + Markdown button to add a text or equation cell.
  • To run a cell, click the play button to the left of the cell or press Shift+Enter.
  • To edit a Markdown cell, double-click on it.

Keyboard Shortcuts

  • Shift+Enter: Run the current cell and move to the next
  • Ctrl+Enter: Run the current cell and stay in that cell
  • Alt+Enter or Opt+Enter: Run the current cell and insert a new cell below
  • Esc: Enter command mode; when in command mode, press h for help

Getting Lab Files

You will receive the lab assignment files from your instructor via Blackboard. Alternatively, you can download the files from the Math Department website. To work with these files:

  1. Download the .ipynb files and save them to a dedicated folder.
  2. Open the folder in VSCode as described earlier.
  3. Click on the .ipynb file to open and begin working on the lab.

Submitting Completed Labs

  1. Make sure all cells have been executed and show the correct output.
  2. Save your notebook file.
  3. To create a PDF for submission:
  • In VSCode, click on the ... menu at the top of the notebook.
  • Select Export.
  • Select HTML from the drop-down menu.
  • Save the HTML file.
  • Open the exported HTML file in an internet browser.
  • Export the file to PDF using the browser.
  1. Upload the PDF file to the course management system as instructed by your professor.

Additional Resources

Good luck with your calculus labs!


Challenge the conventional. Create the exceptional. No Limits.

©