10 Configuring Python with Miniconda
10.1 Why use a dedicated environment?
The examples in this book use a small, fixed collection of scientific Python packages. Installing them in a dedicated Conda environment keeps the course software isolated from the system Python and makes the same notebooks reproducible on Windows, macOS, and Linux.
The recommended setup consists of:
- Miniconda, which supplies Python and the
condaenvironment manager; - the provided
environment.yml, which records the packages and compatible version ranges; - JupyterLab or Visual Studio Code with the official Python and Jupyter extensions.
10.2 Install Miniconda
Download Miniconda from the official installer page and select the installer for your operating system and processor.
Run the graphical installer. The default per-user installation is adequate. After installation, open Miniconda Prompt from the Start menu and use it for the commands in this chapter.
Choose the installer matching the processor reported by About This Mac: Apple silicon (arm64) or Intel (x86_64). After installation, close and reopen Terminal.
Download the shell installer, run it from a terminal, and accept Conda shell initialization when prompted. Close and reopen the terminal afterwards.
Verify that Conda is available:
conda --versionIf the command is not found, open a new terminal. On Windows, use Miniconda Prompt; on macOS or Linux, initialize the current shell once with conda init, then restart it.
10.3 Create the NOOCDS environment
Download the environment description:
Open a terminal in the directory containing the downloaded file and run:
conda env create -f environment.yml
conda activate NOOCDSThe first command creates the environment; the second makes its Python interpreter active in the current terminal. The prompt should now begin with (NOOCDS).
Check the installation:
python --version
python -c "import numpy, scipy, matplotlib, sympy; print('environment ready')"
jupyter --versionThe environment uses the conda-forge channel only. This avoids silently mixing binary packages from incompatible channels.
10.4 Run JupyterLab
Activate the environment and start JupyterLab from the directory in which the notebooks were downloaded:
conda activate NOOCDS
jupyter labJupyter opens in the default web browser. Open a notebook and verify that the kernel displayed in the upper-right corner is Python 3 (ipykernel) from the NOOCDS environment. Use Kernel > Restart Kernel and Run All Cells to reproduce the complete computation from a clean state.
10.5 Optional: Visual Studio Code
Install Visual Studio Code and the official Python and Jupyter extensions. Open the folder containing the examples, then:
- open the Command Palette;
- choose Python: Select Interpreter;
- select the interpreter named
NOOCDS; - open the notebook and select the same environment as its kernel.
The interpreter selected by the editor and the kernel selected by the notebook should refer to the same environment.
10.6 Updating or rebuilding the environment
When environment.yml changes, update an existing installation with
conda activate NOOCDS
conda env update -f environment.yml --pruneThe --prune option removes packages that are no longer part of the declared environment. For a completely clean rebuild:
conda deactivate
conda env remove -n NOOCDS
conda env create -f environment.yml10.7 Common problems
The notebook imports packages from the wrong location. Display the active interpreter from a notebook cell:
import sys
print(sys.executable)Its path must contain the NOOCDS environment. If it does not, change the notebook kernel rather than installing the package again.
The environment name already exists. Use the update command above, or remove the old environment before recreating it.
Plots do not appear. Restart the kernel and run all cells in order. The provided notebooks configure Matplotlib explicitly and do not require a separate graphical backend.