Why the Course Pins Nine Libraries
Every lesson in this course was run against exact library versions, and the values it asks you to compare come from those versions. A different scikit-learn can move a default, reword a warning or change a result in the third decimal place, and then a correct script looks wrong. So you will install exactly these:
| Library | Version | Used for |
|---|---|---|
| scikit-learn | 1.9.1 | Every model, transformer and metric |
| NumPy | 2.5.4 | Arrays; also the seeded random generator |
| SciPy | 1.18.1 | Numerical routines scikit-learn depends on; random distributions for searches |
| pandas | 3.0.6 | Tables in and out of pipelines |
| Matplotlib | 3.11.2 | Charts saved as PNG files |
| joblib | 1.6.0 | Parallel fits and one of the two model file formats |
| skops | 0.16.0 | The safer model file format |
| threadpoolctl | 3.7.0 | Thread control that scikit-learn installs and the parallelism lesson uses |
| pytest | 9.1.1 | Supplied tests in two lessons |
Installing them into your computer's main Python could break other programs
that need different versions. Instead you create a virtual environment: a
folder with its own python command and its own installed libraries. While
the environment is active in a terminal, python in that terminal uses
those libraries; other terminals and programs are unaffected.

Read the diagram from the outside in. The grey box is your computer's own
Python. Inside your home folder, the practice folder holds three kinds of
thing: the environment .venv, which you keep for the whole course; the file
requirements.txt, which lists the exact versions so that the environment
can be rebuilt at any time; and one folder per lesson, named after the
lesson, which you remove when the lesson is finished.
Which Python You Need
The course supports Python 3.12 to 3.15. Python 3.12 is the oldest version the pinned libraries accept: NumPy 2.5.4 and SciPy 1.18.1, which scikit-learn installs alongside itself, both require it. Python 3.15.0, released on 9 October 2026, is the newest. For every version in that range, the compiled libraries publish ready-built packages for Windows, macOS and Linux, so installation needs no compiler. A Python newer than 3.15 may fail to install them until such packages exist.
Check what you have. On macOS and Linux:
python3 --version
In Windows PowerShell:
python --version
Illustrative output:
Python 3.14.4
If the command is not found, or the version is below 3.12, install Python first:
- Windows: install the Python Install Manager from python.org/downloads or
from the Microsoft Store, then open a new PowerShell window. It provides
the
pythoncommand. - macOS: use the installer from python.org/downloads, then open a new Terminal window.
- Linux: most distributions include Python. If yours is older than 3.12,
install a newer version with your distribution's package manager. On
Debian, Ubuntu and their derivatives, the
venvmodule is packaged separately: installpython3-venv(or the versioned package, such aspython3.12-venv) before step 2 below.
Terminal Commands You Will Use
The exercises use four terminal commands to move around and one to clean up. On macOS and Linux they work in the standard shell; Windows PowerShell accepts the first four names and has its own command for the fifth:
pwdprints the folder you are in.lslists the files and folders in it.cd <folder>moves into a folder;cd ~returns to your home folder.mkdir <folder>creates a folder.rm -r <folder>deletes a folder and everything in it. There is no recycle bin and no undo, so every lesson lists the folder withlsfirst and removes only that lesson's own folder. Later cleanups writerm -rf, where-falso stopsrmfrom asking about protected files. In PowerShell the command isRemove-Item <folder>, with-Recursefor a folder that is not empty.
Commands that differ by platform are shown twice in every lesson: once for
macOS and Linux, once for Windows PowerShell. Run only the version for your
computer. After the environment is active, every Python command is the same
on all three: python <script>.py.
Exercise: Create the Course Environment
You will create the practice folder, the course environment inside it, the list of pinned versions and a check script, then confirm that the check script sees the right versions from the right place.
Starting state: Python 3.12 to 3.15 installed; no sklearn-practice
folder yet. The installation downloads about 470 MB of packages, so this is
the one exercise that needs the network.
-
Check the terminal commands. macOS and Linux:
pwd mkdir -p ~/sklearn-practice/terminal-check cd ~/sklearn-practice/terminal-check pwd ls cd ~/sklearn-practice rm -r terminal-check lsWindows PowerShell:
pwd mkdir $HOME\sklearn-practice\terminal-check cd $HOME\sklearn-practice\terminal-check pwd ls cd $HOME\sklearn-practice Remove-Item terminal-check lsThe second
pwdprints a path ending insklearn-practice/terminal-check(sklearn-practice\terminal-checkon Windows), andlsthere prints nothing because the folder is empty. The lastlsno longer showsterminal-check. The-poption on macOS and Linux creates any missing parent folders, heresklearn-practiceitself. -
Create and activate the environment. macOS and Linux:
cd ~/sklearn-practice python3 -m venv .venv source .venv/bin/activate python --versionWindows PowerShell:
cd $HOME\sklearn-practice python -m venv .venv .venv\Scripts\Activate.ps1 python --versionpython3 -m venv .venvruns Python's built-invenvmodule, which creates the environment in a folder named.venv. Activation changes whichpythonthis terminal uses, and your prompt now starts with(.venv). From here on the command ispythonon every platform, because the active environment provides it. -
Save the list of pinned libraries. In your editor, create a file in your
sklearn-practicefolder. Save this asrequirements.txt:scikit-learn==1.9.1 numpy==2.5.4 scipy==1.18.1 pandas==3.0.6 matplotlib==3.11.2 joblib==1.6.0 skops==0.16.0 threadpoolctl==3.7.0 pytest==9.1.1Each line names a library and, after
==, the exact version to install. -
Install the libraries into the active environment:
python -m pip install -r requirements.txtpipis Python's package installer. Running it aspython -m pipmakes sure it is the environment's own copy, and-r requirements.txttells it to read the list you saved. It also installs the few libraries these nine depend on. This can take a few minutes; the last line starts withSuccessfully installed. -
Create the lesson folder and the check script. macOS and Linux:
mkdir -p ~/sklearn-practice/set-up-the-environment cd ~/sklearn-practice/set-up-the-environmentWindows PowerShell:
mkdir $HOME\sklearn-practice\set-up-the-environment cd $HOME\sklearn-practice\set-up-the-environmentSave this as
check_setup.pyin that folder:"""Check the course environment: Python version, location and the pinned libraries.""" import sys import joblib import matplotlib import numpy import pandas import pytest import scipy import skops import sklearn import threadpoolctl print("Python:", sys.version.split()[0]) print("Environment:", sys.prefix) print("Python supported:", (3, 12) <= sys.version_info[:2] <= (3, 15)) expected = { "scikit-learn": (sklearn.__version__, "1.9.1"), "NumPy": (numpy.__version__, "2.5.4"), "SciPy": (scipy.__version__, "1.18.1"), "pandas": (pandas.__version__, "3.0.6"), "Matplotlib": (matplotlib.__version__, "3.11.2"), "joblib": (joblib.__version__, "1.6.0"), "skops": (skops.__version__, "0.16.0"), "threadpoolctl": (threadpoolctl.__version__, "3.7.0"), "pytest": (pytest.__version__, "9.1.1"), } for name, (found, wanted) in expected.items(): result = "OK" if found == wanted else f"expected {wanted}" print(f"{name}: {found} {result}")Run it:
python check_setup.pyIllustrative output on Linux:
Python: 3.14.4 Environment: /home/you/sklearn-practice/.venv Python supported: True scikit-learn: 1.9.1 OK NumPy: 2.5.4 OK SciPy: 1.18.1 OK pandas: 3.0.6 OK Matplotlib: 3.11.2 OK joblib: 1.6.0 OK skops: 0.16.0 OK threadpoolctl: 3.7.0 OK pytest: 9.1.1 OK
How the Check Script Works
The nine import lines load the libraries. If the environment is not
active, the first one that is missing stops the script with
ModuleNotFoundError, which is itself a useful check. scikit-learn is
imported as sklearn: the name you install and the name you import differ.
sys.version holds the full Python version text, and .split()[0] keeps
its first word, the version number. sys.prefix is the folder of the Python
that is running; with the environment active, it is the .venv folder.
sys.version_info[:2] gives the major and minor version as a pair such as
(3, 14), and Python compares pairs item by item, so the
(3, 12) <= ... <= (3, 15) test is True only inside the supported range.
Each library stores its version in __version__. The expected dictionary
pairs each found version with the wanted one, and the loop prints OK or the
version the course expects. If you installed from requirements.txt into the
active environment, every line ends in OK.
Success: Python supported is True, all nine library lines end in
OK, and the Environment line ends in sklearn-practice/.venv
(sklearn-practice\.venv on Windows).
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
python3 or python is not found | Python is not installed, or the terminal was opened before installation | Install Python as described above, then open a new terminal |
| A version below 3.12 | An older Python is installed | Install a supported version; recreate the environment with it |
PowerShell refuses to run Activate.ps1 because running scripts is disabled | Windows does not allow local scripts for your account | See the note after this table |
python3 -m venv says that ensurepip is not available | Debian, Ubuntu and their derivatives package venv support separately | Install python3-venv (or the versioned package for your Python), then repeat step 2 |
pip prints errors about building a package or a missing compiler | Your Python version has no ready-built package for a pinned library | Check python --version; use Python 3.12 to 3.15 |
ModuleNotFoundError: No module named 'joblib' or another of the nine | The environment is not active in this terminal | Activate it as in step 2, then rerun |
Environment: shows a path outside sklearn-practice | The terminal is running another Python | Activate the environment; on Windows without activation, run ..\.venv\Scripts\python check_setup.py |
A library line ends with expected ... | Another version is installed in the environment, for example an older scikit-learn that was already on the path | Run step 4 again in the active environment; pip replaces the wrong version |
Activating on Windows: Python's documentation notes that you may first need to allow local scripts for your user account with this PowerShell command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
It changes a Windows security setting for your account only; read
Microsoft's "About Execution Policies" page, linked from the Python
documentation, before running it. If you prefer not to change it, skip
activation and type .venv\Scripts\python instead of python in every
command, including ..\.venv\Scripts\python check_setup.py from a lesson
folder. The environment works without activation; activation only saves
typing.
Reset: an environment is disposable because requirements.txt describes
it. If it ever breaks, remove .venv and build it again from that file.
First deactivate the environment and check you are in the practice folder.
macOS and Linux:
deactivate
cd ~/sklearn-practice
ls -a
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
Windows PowerShell:
deactivate
cd $HOME\sklearn-practice
ls -Force
Remove-Item -Recurse .venv
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
Check that ls -a (ls -Force on Windows) lists .venv and
requirements.txt before you remove anything. Afterwards, rerun the check
script; it prints the same nine OK lines.
-
Clean up the lesson folder, keeping the environment. macOS and Linux:
cd ~/sklearn-practice ls rm -rf set-up-the-environment lsWindows PowerShell:
cd $HOME\sklearn-practice ls Remove-Item -Recurse set-up-the-environment lsCheck that the first
lsshowsset-up-the-environmentbefore you remove it. Do not remove.venvorrequirements.txt: every later lesson uses them.
Independent task: before step 6, open a new terminal window, go to
the lesson folder and run the check script without activating the
environment (python3 check_setup.py on macOS and Linux,
python check_setup.py on Windows). Predict what happens first, then run
it. Then activate the environment in that terminal, run it again and explain
the difference.
Check Your Understanding
Three learners report problems:
- "My terminal says
command not found: python3." - "The check script says
Python 3.11.9andPython supported: False." - "It worked yesterday, but today it stops at
No module named 'joblib'."
For each, name the cause and the fix.
Answer and Reasoning
Independent task
Without activation, the terminal runs your computer's own Python, which does
not have the course's libraries. On most computers it stops at once with a
line ending in No module named 'joblib', because joblib is the first
import in the script and is not installed there. If your computer's Python
happens to have some of the nine, the script stops at the first one it
lacks, or runs and prints expected ... on the lines whose versions differ,
with an Environment: path outside sklearn-practice. After activating the
environment in that terminal, the script prints the nine OK lines again.
Activation applies to one terminal at a time, so every new terminal needs
it.
Understanding check
- Python is not installed, or the terminal was opened before it was installed. Install a supported Python and open a new terminal.
- Python 3.11 is below the course minimum, because NumPy 2.5.4 and SciPy
1.18.1 need 3.12 or later. Install Python 3.12 to 3.15 and recreate the
environment with it;
pipwould otherwise try to build the libraries from source or refuse them. - The environment is not active in today's terminal. Activation lasts only for the terminal where you ran it. Activate it again; there is nothing to reinstall.
References
- S01: PyPI: scikit-learn 1.9.1
- S02: Installing scikit-learn
- S09: PyPI: NumPy 2.5.4
- S12: PyPI: skops 0.16.0
- S41: PyPI JSON: SciPy 1.18.1
- S42: PyPI JSON: pandas 3.0.6
- S43: PyPI JSON: Matplotlib 3.11.2
- S44: PyPI JSON: joblib 1.6.0
- S45: PyPI JSON: pytest 9.1.1
- S46: PyPI JSON: threadpoolctl 3.7.0
- S47: Python developer guide: status of Python versions