Setting Up Your Environment

Install the libraries with pip or conda and confirm they import correctly.

Syntaxpip install numpy pandas scikit-learn

Before writing AI code you need the libraries installed. The two common package managers are pip and conda.

Installing with pip

pip install numpy pandas matplotlib scikit-learn seaborn jupyter

Check it worked

Import each library and print its version. If there are no errors, you are ready.

Using a virtual environment (venv or conda env) per project keeps versions from clashing.

Example

Example · python
import numpy, pandas, sklearn, matplotlib

print('numpy', numpy.__version__)
print('pandas', pandas.__version__)
print('sklearn', sklearn.__version__)
# numpy 1.26.4
# pandas 2.2.2
# sklearn 1.5.0

When to use it

  • A developer creates an isolated conda environment for each ML project so different projects can pin different numpy and scikit-learn versions without conflict.
  • A CI pipeline runs pip install -r requirements.txt before training to guarantee every team member and server uses the same library versions.
  • A new team member follows the setup script to install the full AI stack and verify it with version prints before touching any code.

More examples

Install AI stack with pip

Creates a virtual environment, activates it, and installs the complete Python AI stack in one pip command.

Example · bash
python -m venv .venv
source .venv/bin/activate
pip install numpy pandas matplotlib scikit-learn seaborn jupyter torch

Verify imports and versions

Imports each library and prints its version so you can confirm the environment is set up correctly before starting a project.

Example · python
import numpy as np
import pandas as pd
import sklearn
import matplotlib
import seaborn

for name, mod in [('numpy', np), ('pandas', pd), ('sklearn', sklearn),
                   ('matplotlib', matplotlib), ('seaborn', seaborn)]:
    print(f'{name}: {mod.__version__}')

Freeze requirements for reproducibility

Captures the exact versions of all installed packages into requirements.txt, ensuring every collaborator or deployment uses an identical environment.

Example · bash
pip freeze > requirements.txt
# Share with teammates:
pip install -r requirements.txt

Discussion

  • Be the first to comment on this lesson.