Installing Data Science Libraries (pip & conda)
Data science libraries you’ll use often
Section titled “Data science libraries you’ll use often”A common starter stack for data analytics includes:
- NumPy: numerical computing
- Pandas: data manipulation
- Matplotlib: plotting foundation
- Seaborn: statistical visualization
- Plotly: interactive charts
- Jupyter: notebooks
- SciPy (optional early): scientific utilities
- scikit-learn (later): ML utilities
pip vs conda (how to choose)
Section titled “pip vs conda (how to choose)”Use conda when
Section titled “Use conda when”- You’re using Anaconda/Miniconda
- You want fewer build/compile issues
- You need compiled dependencies (common in data science)
Use pip when
Section titled “Use pip when”- You installed CPython from python.org
- You’re inside a
venv - A package isn’t available via conda
Installing with conda
Section titled “Installing with conda”Step 1: Create and activate an environment
Section titled “Step 1: Create and activate an environment”conda create -n analytics python=3.12conda activate analyticsStep 2: Install the core stack
Section titled “Step 2: Install the core stack”conda install numpy pandas matplotlib seaborn jupyterStep 3: Install Plotly
Section titled “Step 3: Install Plotly”Plotly is often available via conda, but some users prefer pip. Try conda first:
conda install plotlyIf not available in your channels, use pip:
pip install plotlyInstalling with pip (venv)
Section titled “Installing with pip (venv)”Step 1: Create and activate
Section titled “Step 1: Create and activate”python -m venv .venvsource .venv/bin/activateStep 2: Install packages
Section titled “Step 2: Install packages”pip install numpy pandas matplotlib seaborn plotly jupyterVerifying installs in Python
Section titled “Verifying installs in Python”After installing packages, verify them in a Python session or notebook:
import numpy as np
import pandas as pd
import matplotlib
import seaborn as sns
import plotly
print("NumPy:", np.__version__)
print("Pandas:", pd.__version__)
print("Matplotlib:", matplotlib.__version__)
print("Seaborn:", sns.__version__)
print("Plotly:", plotly.__version__)Installing Jupyter kernel for your environment
Section titled “Installing Jupyter kernel for your environment”Sometimes Jupyter is installed globally but you want the kernel to point at your environment.
Install ipykernel:
pip install ipykernelRegister the kernel:
python -m ipykernel install --user --name analytics --display-name "Python (analytics)"Now your environment appears in Jupyter kernel selection.
Reproducibility: pinning versions
Section titled “Reproducibility: pinning versions”For long projects, pin versions so your notebook still runs months later.
pip: requirements.txt
Section titled “pip: requirements.txt”numpy==2.1.0
pandas==2.2.3
matplotlib==3.9.2
seaborn==0.13.2
plotly==5.24.1
jupyter==1.1.1conda: environment.yml
Section titled “conda: environment.yml”name: analytics
channels:
- conda-forge
dependencies:
- python=3.12
- numpy
- pandas
- matplotlib
- seaborn
- plotly
- jupyterVisualize it
Section titled “Visualize it”Use this decision path whenever you’re not sure which installer to reach for.
flowchart TD
A["Need to install a package"] --> B{"Environment created with conda?"}
B -->|"Yes"| C["Try: conda install package"]
C --> D{"Available on conda-forge?"}
D -->|"Yes"| E["Installed via conda"]
D -->|"No"| F["Fallback: pip install package"]
B -->|"No (venv/plain Python)"| G["pip install package"]
Common errors and fixes
Section titled “Common errors and fixes”Error: ModuleNotFoundError: No module named 'pandas'
Section titled “Error: ModuleNotFoundError: No module named 'pandas'”- You installed in one environment but are running Python from another.
- Solution: activate the correct environment and reinstall.
Error: Jupyter doesn’t show the right kernel
Section titled “Error: Jupyter doesn’t show the right kernel”- Install and register
ipykernelas shown above.
Error: pip installs but import fails
Section titled “Error: pip installs but import fails”- Check you’re using the intended
pip:- In a terminal inside the environment, run
which pip(macOS/Linux) - Or
where pip(Windows)
- In a terminal inside the environment, run
Phase 1 is complete. Next we’ll start Phase 2: Numerical Computing (NumPy) with an Introduction to NumPy.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Choose pip or conda
Section titled “Exercise 1 – Choose pip or conda”Exercise 2 – Build a requirements.txt From a Dict
Section titled “Exercise 2 – Build a requirements.txt From a Dict”Exercise 3 – Verify Imports Like a Setup Script
Section titled “Exercise 3 – Verify Imports Like a Setup Script”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading