Why the Course Uses Its Own Environment
Every practical lesson runs Python scripts that use four libraries: NumPy for arrays of numbers, pandas for tables, scikit-learn for machine learning models and Matplotlib for charts. Libraries change between releases: a default value moves, a warning is reworded, a result shifts in the third decimal place. The lessons were checked against one exact version of each, so you will install those versions:
| Library | Version |
|---|---|
| NumPy | 2.5.4 |
| pandas | 3.0.6 |
| scikit-learn | 1.9.1 |
| Matplotlib | 3.11.2 |
Installing them into your computer's main Python could break other programs
that need different versions. Instead, you will create a virtual
environment: a folder containing its own Python command and its own set of
installed libraries. While the environment is active in a terminal, the
python command in that terminal uses the environment's libraries; other
terminals and programs are unaffected.
Terminal Commands You Will Use
The exercises use four terminal commands. On macOS and Linux they work in the standard shell; Windows PowerShell accepts the same four names:
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.
The exercise below starts with a short check of these commands. If they are new to you, run that check slowly and compare each result with the description.
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, all four libraries publish ready-built packages for Windows, macOS and Linux, so the installation needs no compiler. A newer Python than 3.15 may fail to install the libraries until such packages exist.
Check what you have. On macOS and Linux:
python3 --version
In Windows PowerShell:
python --version
Illustrative output:
Python 3.15.0
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. The libraries' ready-built packages need macOS 12 or later on a Mac with Apple silicon, or macOS 10.15 or later on an Intel Mac.
- Linux: most distributions include Python. If yours is older than 3.12, install a newer version with your distribution's package manager.
Exercise: Create the Course Environment
You will create the practice folder, the course environment inside it, and a check script that confirms everything is in place.

Read the diagram from top to bottom. The outer box is your computer's own
Python. The inner box is the course environment: once you activate it, the
python command in that terminal resolves to the environment, which holds the
pinned libraries. The exercise folders below it are plain folders; what
matters is which environment is active when you run a script in them.
Starting state: Python 3.12 to 3.15 installed; no ai-practice folder yet.
Commands that differ by platform are shown twice: once for macOS and Linux,
once for Windows PowerShell. Run only the version for your computer.
-
Check the terminal commands. macOS and Linux:
pwd mkdir -p ~/ai-practice/terminal-check cd ~/ai-practice/terminal-check pwd ls cd ~/ai-practice rm -r terminal-check lsWindows PowerShell:
pwd mkdir $HOME\ai-practice\terminal-check cd $HOME\ai-practice\terminal-check pwd ls cd $HOME\ai-practice Remove-Item terminal-check lsThe second
pwdprints a path ending inai-practice/terminal-check(ai-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, hereai-practiceitself. -
Create and activate the environment. macOS and Linux:
cd ~/ai-practice python3 -m venv .venv source .venv/bin/activate python --versionWindows PowerShell:
cd $HOME\ai-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. The leading dot is a common convention; on macOS and Linux it also hides the folder from a plainls. 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 named
requirements.txtin yourai-practicefolder. Save this asrequirements.txt:numpy==2.5.4 pandas==3.0.6 scikit-learn==1.9.1 matplotlib==3.11.2Each 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 downloads about 450 MB of files, including libraries these four depend on, such as SciPy. This can take a few minutes; the last line starts withSuccessfully installed. -
Create the exercise folder and the check script. macOS and Linux:
mkdir -p ~/ai-practice/course-environment cd ~/ai-practice/course-environmentWindows PowerShell:
mkdir $HOME\ai-practice\course-environment cd $HOME\ai-practice\course-environmentSave this as
check_setup.pyin that folder:"""Check the course environment: Python version, location and pinned libraries.""" import sys import matplotlib import numpy import pandas import sklearn print("Python:", sys.version.split()[0]) print("Environment:", sys.prefix) print("Python supported:", (3, 12) <= sys.version_info[:2] <= (3, 15)) expected = { "NumPy": (numpy.__version__, "2.5.4"), "pandas": (pandas.__version__, "3.0.6"), "scikit-learn": (sklearn.__version__, "1.9.1"), "Matplotlib": (matplotlib.__version__, "3.11.2"), } 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.15.0 Environment: /home/you/ai-practice/.venv Python supported: True NumPy: 2.5.4 OK pandas: 3.0.6 OK scikit-learn: 1.9.1 OK Matplotlib: 3.11.2 OK
How the Check Script Works
The four import lines load the libraries. If the environment is not active,
the first missing one stops the script with an error, which is itself a useful
check. Note that 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 only
its first word, the version number. sys.prefix is the folder of the Python
installation 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, 15), 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 changed "2.5.4" to "2.0.0", the NumPy
line would end with expected 2.0.0 while the library itself stayed
unchanged: the script only reports.
Success: Python supported is True, all four library lines end in OK,
and the Environment line ends in ai-practice/.venv
(ai-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 | Some Linux distributions package the venv support separately | Install your distribution's venv package for your Python version (on Debian and Ubuntu, python3.12-venv for Python 3.12), 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 'matplotlib' | The environment is not active in this terminal | Activate it as in step 2, then rerun |
A library line ends with expected ... | Another version is installed in the environment | Run step 4 again in the active environment |
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 an exercise folder. The
environment works without activation; activation only saves typing.
-
Clean up the exercise folder, keeping the environment. macOS and Linux:
cd ~/ai-practice ls rm -rf course-environment lsWindows PowerShell:
cd $HOME\ai-practice ls Remove-Item -Recurse course-environment lsCheck that the first
lsshowscourse-environmentbefore you remove it. Do not remove.venvorrequirements.txt: every later lesson uses them.
Independent task: before step 7, open a new terminal window, go to the
exercise folder and run the check 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 the check again and explain the difference.
Check Your Understanding
Three learners report problems:
- "My terminal says
command not found: python3." - "It says
Python 3.11.9." - "It worked yesterday, but today it says
ModuleNotFoundError: No module named 'matplotlib'."
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 the script stops at the
first import with ModuleNotFoundError: No module named 'matplotlib'. If your
computer's Python happens to have Matplotlib, the error comes at a later
import, or the script runs but the Environment line shows a folder other
than .venv and some versions differ from the pinned ones. After activating
the environment in that terminal, the check prints four 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 needs 3.12 or later. Install Python 3.12 to 3.15 and recreate the environment with it.
- 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: PyPI: NumPy 2.5.4
- S03: PyPI: pandas 3.0.6
- S04: PyPI: Matplotlib 3.11.2
- S05: PyPI: SciPy 1.18.1
- S06: scikit-learn installation guide (source)
- S07: Python 3.15 documentation: venv (source)
- S08: PEP 790: Python 3.15 Release Schedule
- S09: PEP 693: Python 3.12 Release Schedule
- S28: scikit-learn 1.9 release notes
- S49: Python 3.15 documentation: Using Python on Windows (source)
- S50: Python 3.15 documentation: Using Python on macOS (source)
- S51: Python 3.15 documentation: Using Python on Unix platforms (source)
- S53: Python Packaging User Guide: Installing pip/setuptools/wheel with Linux Package Managers (source)