Appendix C — Python Setup Guide

This book teaches calculus first and Python second. You do not need any prior programming experience, and you will never be asked to "write a program." The code in this book exists for one purpose: to let you check your hand calculations and see the shapes calculus describes. When you compute a derivative on paper, you can type three lines and confirm the machine agrees. When a curve is hard to imagine, you can plot it.

This appendix is the one place where install commands live. Other appendices and chapters assume you have followed this guide once and have a working Python with the four core libraries. Read whichever option below fits you, do it once, and you are done for the whole book. If you are nervous about installing software, skip straight to Option C — it requires installing nothing at all.

What You Need and Why

You need Python 3.10 or newer plus four libraries: numpy, scipy, sympy, and matplotlib. Optionally, jupyter gives you the notebook interface this book is written in.

Here is what each one does, in one breath. sympy does symbolic math — it manipulates the letters x and y the way you do on paper, so sp.diff(x**2, x) returns 2*x, an exact answer. numpy does numerical math on big lists of numbers fast; we use it for Riemann sums, finite differences, and generating the points that make a smooth curve. scipy builds on numpy with ready-made tools for numerical integration, solving differential equations, and optimization (the SIR epidemic model in Chapter 19 leans on it). matplotlib draws every graph in the book. jupyter is not math at all — it is the "notebook" that lets you mix text, code, and plots in one document and run code one chunk ("cell") at a time, which is the friendliest way to learn.

You only ever need Python 3.10+ and those four libraries. Everything else is optional convenience.

Option A — The Easy Path: Anaconda or Miniconda

Anaconda is a single installer that bundles Python and almost every scientific library, including all four of ours. It is the most reliable choice for beginners on any operating system because it avoids version headaches.

Install (Windows, macOS, or Linux):

  1. Download the installer from https://www.anaconda.com/download (full Anaconda, ~700 MB, includes everything) or https://docs.conda.io/en/latest/miniconda.html (Miniconda, ~50 MB, minimal — you add libraries yourself).
  2. Run the installer and accept all defaults. On Windows, this is a normal .exe wizard. On macOS, a .pkg wizard. On Linux, run the downloaded .sh file with bash Anaconda3-2024.xx-Linux-x86_64.sh and answer "yes" to the prompts.
  3. Open Anaconda Navigator (search for it in your Start menu / Applications), then click Launch under JupyterLab. A notebook environment opens in your browser.

If you installed full Anaconda, numpy, scipy, sympy, and matplotlib are already there — skip to "Verify Your Installation."

Optional but recommended — create a dedicated environment. An "environment" is a private sandbox for this book's libraries so it cannot disturb anything else on your computer. Open the Anaconda Prompt (Windows) or your terminal (macOS/Linux) and run:

conda create -n calculus python=3.11 numpy scipy sympy matplotlib jupyter
conda activate calculus

You will see (calculus) appear at the start of your prompt, meaning the sandbox is active. To leave it later, type conda deactivate. To return, conda activate calculus.

Option B — Plain Python + pip + Virtual Environments

If you prefer the official Python (no Anaconda), install it, then create a virtual environment (the plain-Python equivalent of a conda environment) and pip-install the libraries.

  1. Download Python 3.10+ from https://www.python.org/downloads/. On Windows, check the box "Add Python to PATH" during installation — this is the single most common thing beginners forget.
  2. Create and activate a virtual environment. Open a terminal in a folder where you want this book's work to live, then:

Windows (PowerShell): powershell python -m venv calc-env calc-env\Scripts\Activate.ps1

Windows (Command Prompt): cmd python -m venv calc-env calc-env\Scripts\activate.bat

macOS / Linux: bash python3 -m venv calc-env source calc-env/bin/activate

When active, (calc-env) appears at the start of your prompt. Type deactivate to exit.

  1. Install the four libraries (plus jupyter) with pip:

bash pip install numpy scipy sympy matplotlib jupyter

That command is all you need. If pip is not recognized, try pip3 instead (see Troubleshooting).

If installing anything feels intimidating, do this instead. Google Colab runs Jupyter notebooks entirely in your web browser on Google's computers. You need only a free Google account and an internet connection — nothing to download, nothing to break.

  1. Go to https://colab.research.google.com/.
  2. Sign in with a Google account and click New notebook.
  3. Start typing code. numpy, scipy, sympy, and matplotlib are already pre-installed — no setup at all.

Colab is the path of least resistance and works identically on a school Chromebook, a Mac, or a Windows laptop. (Other browser options exist — JupyterLite, Replit, Binder — but Colab is the smoothest for this book.)

How to Run the Book's Code

The same few lines of Python run the same way no matter which option you chose. Here are the four contexts you might use:

  • In a Jupyter notebook or Colab: Type code into a cell and press Shift+Enter. The output (or a plot) appears directly below the cell. This is the recommended way to follow along, because you can edit and re-run a calculation instantly.
  • In a .py script from the terminal: Save your code in a file such as test.py, then run python test.py (or python3 test.py). Note that in a script you must use print(...) to see results, and plt.show() to pop up a plot window.
  • In the Python REPL: Type python (or python3) in your terminal to get an interactive >>> prompt. Paste code line by line; results print automatically. Type exit() to leave.

Your First "Hello, Calculus"

Try this anywhere — a notebook cell, Colab, a script, or the REPL:

import sympy as sp

x = sp.symbols('x')          # tell sympy x is a math variable
print(sp.diff(x**2, x))      # differentiate x squared with respect to x

Expected output:

2*x

If you see 2*x, your installation works and you are ready for the whole book. To go one step further, confirm the derivative-integral round trip:

import sympy as sp

x = sp.symbols('x')
print(sp.diff(x**3, x))      # 3*x**2
print(sp.integrate(x**2, x)) # x**3/3

A Plotting Check

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-5, 5, 100)  # 100 evenly spaced points from -5 to 5
plt.plot(x, np.sin(x))
plt.title('Test plot: y = sin(x)')
plt.show()

A sine wave should appear. In a Jupyter/Colab cell, the plot shows automatically; in a .py script, plt.show() opens the window.

Using the requirements.txt File

This book's repository includes a requirements.txt at its root that pins the versions everything was tested against:

numpy>=1.24
scipy>=1.11
sympy>=1.12
matplotlib>=3.7
jupyter>=1.0
ipykernel>=6.0
jupyter-book>=0.15

Instead of typing each library by hand, you can install them all at once. From the repository folder (with your environment active), run:

pip install -r requirements.txt

This is the recommended way if you have downloaded the book's source, because it guarantees you get compatible versions. (The last two lines, ipykernel and jupyter-book, are only needed if you want to build the book yourself — see the note at the end.)

Troubleshooting

  • "python is not recognized / command not found." Python is not on your PATH. On Windows, re-run the installer and tick "Add Python to PATH," or use the Anaconda Prompt which sets it up for you. On macOS/Linux, try python3 instead of python.
  • pip vs pip3. On systems with both Python 2 and 3, pip may point at the wrong one. Use pip3, or the always-correct form python -m pip install ... (substitute python3 on macOS/Linux), which guarantees pip matches the Python you are running.
  • Multiple Python versions / "I installed it but it's not there." You likely installed the library into a different Python than the one you are running. Activate your environment first (conda activate calculus or source calc-env/bin/activate), then install — this keeps one Python and its libraries together. Running python -m pip install <name> from inside the active environment is the foolproof fix.
  • ModuleNotFoundError: No module named '...'. That library is not installed in the active environment. Install it with pip install <name> (e.g., pip install sympy) while the environment is active.
  • Plots do not appear. In a Jupyter notebook, add %matplotlib inline as the first line of a cell once per session. In a .py script, make sure you called plt.show(). In Colab, plots show automatically — no extra step needed.
  • Jupyter "kernel" errors or the wrong Python in a notebook. The notebook is connected to a different Python than where you installed the libraries. With your environment active, run python -m ipykernel install --user --name calculus, then in Jupyter pick that kernel via Kernel → Change Kernel. If a kernel hangs, Kernel → Restart clears it.
  • Permission errors during pip install (especially Access is denied / Permission denied). Do not reach for sudo. The clean fix is to install inside a virtual environment (Option B) where you own all the files, or add --user: pip install --user numpy scipy sympy matplotlib.
  • First run is slow. The very first import of a large library compiles caches; this is normal and one-time. Wait a few seconds.

A Note on the Dual Build System

This textbook ships in two forms. The mdBook version is the readable book — clean HTML pages you browse like any website, where the Python appears as static, syntax-highlighted listings with their expected output shown inline. You do not need Python at all to read it. The Jupyter Book version is the computational book — the same chapters as live notebooks where every code block can be run, edited, and re-plotted in your browser or locally. If you only want to read, use mdBook and ignore this appendix. If you want to run and experiment, set up Python with any option above and use the Jupyter Book version. Building the book yourself (with jupyter-book) is entirely optional and needed only by instructors or contributors, not by readers working through the chapters.