Install NumPy and pandas

Install NumPy and pandas for data in this Applied AI engineering tutorial — hands-on steps, troubleshooting, and what to study next.

Focus: install numpy and pandas for data

Sponsored

You've just solved the hardest 80% of machine learning — you have a real dataset, real questions, and real motivation. But when you type import pandas as pd, you get a wall of red ModuleNotFoundError. That's the exact pain this lesson eliminates. By the end, you'll have NumPy and pandas installed in a clean, reproducible environment, and you'll know exactly how to verify the installation, fix the most common errors, and avoid the mess that derails most beginners. Let's set up your data science foundation in minutes — and make it stick.

The problem this lesson solves

Every applied AI project — from cleaning customer data to training a model — starts with the same two libraries. NumPy gives you fast, array-based math. pandas gives you labeled, tabular data structures like DataFrames. Without them, you're forced to reinvent basic data handling, and your code becomes slow and unreadable.

The real problem? Installation is not a one-liner. You'll face: - ModuleNotFoundError because the package didn't install into the same Python interpreter you're using. - Permission errors when trying to install into a system-owned directory. - Conflicting versions when a previous project installed a different pandas version.

Only understanding where packages go and how to isolate them will save you time and frustration. This lesson teaches you exactly that.

Why this matters right now: Every later lesson in this track — data cleaning, feature engineering, even model training — assumes you have NumPy and pandas working. Fix this step, and the rest becomes smooth.

Core concept / mental model

Think of your Python environment as a personal kitchen. The kitchen (system Python) has a few basic tools (standard library). NumPy and pandas are specialty appliances — powerful, but not pre-installed. You need to install them into the right kitchen, because a tool in your upstairs kitchen won't help you in the basement.

Key terms: - Package – a collection of code, like pandas, distributed via PyPI (the Python Package Index). - Dependency – pandas depends on NumPy, so installing pandas often pulls NumPy automatically. - Environment – an isolated Python installation with its own packages. - Virtual environment – a folder that contains its own Python and packages, keeping projects independent.

The command pip install pandas downloads the package and its dependencies into your current environment. If you run it in a different environment than the one you code in, you'll get ModuleNotFoundError. That's why we use a virtual environment — it's your dedicated kitchen for this project.

How it works step by step

  1. Create a project folder – keep all project files together.
  2. Create a virtual environment – this isolates your project's packages.
  3. Activate the environment – tell your shell to use the environment's Python.
  4. Install NumPy and pandas – use pip to fetch from PyPI.
  5. Verify the installation – import both libraries and check versions.

Each step builds on the last, and the order matters. Skipping activation is the #1 cause of "I installed it but can't import it."

Hands-on walkthrough

Let's do it for real. Open a terminal and run the following. Here's the complete sequence:

# 1. Create and enter a project folder
mkdir ai-data-project && cd ai-data-project

# 2. Create a virtual environment
python -m venv .venv

# 3. Activate it
# Windows (Command Prompt):
.venv\Scripts\activate
# macOS / Linux / Git Bash:
source .venv/bin/activate

# 4. Install pandas (which pulls NumPy) and also explicitly install NumPy
pip install numpy pandas

# 5. Verify
python -c "import numpy, pandas; print('NumPy', numpy.__version__); print('pandas', pandas.__version__)"

Expected output (versions may differ):

NumPy 1.26.4
pandas 2.2.2

Now let's test a real data operation — just to be 100% sure it works:

import numpy as np
import pandas as pd

# Create a small dataset
array = np.array([10, 20, 30, 40])
df = pd.DataFrame({'values': array, 'squared': array ** 2})

print(df)
print(f"Mean: {df['values'].mean()}")

Output:

   values  squared
0      10      100
1      20      400
2      30      900
3      40     1600
Mean: 25.0

See? NumPy handles the fast math, pandas gives the nice table. Both are working together.

Compare options / when to choose what

You might wonder: should you use pip or something else? Here's a comparison:

Method Best for Pros Cons
pip inside virtual env Simple projects, learning Lightweight, standard, no extra layer You manage dependencies manually
conda Data science, complex dependencies Handles non-Python libs (e.g., BLAS), nice env manager Heavier, its own package source
pip with requirements.txt Reproducible projects, team work Locks versions, easy to replicate Still use virtual env
poetry Professional app development Dependency resolution, packaging More to learn

Recommendation: For this track, use pip + virtual environment. It's the standard, simple, and enough for applied AI work. If you hit a binary dependency issue (like a missing BLAS), consider conda — but don't start with it.

Troubleshooting & edge cases

Even with clear steps, you might see errors. Here's how to fix them:

  • ModuleNotFoundError: No module named 'pandas' – You likely activated the wrong environment, or didn't activate at all. Run which python (or where python on Windows). The path should point inside .venv. If not, activate again.

  • Permission denied during install – You're installing to a system Python. Don't use sudo pip. Instead, create a virtual environment. If you already did, check folder permissions.

  • pip command not found – Older Python may not have pip. Use python -m pip instead of pip.

  • Import works in terminal but not in your editor – The editor is using a different interpreter. In VS Code, select the interpreter from the Command Palette (Ctrl+Shift+P → “Python: Select Interpreter”) and choose the one from .venv.

  • pandas version conflict – If you have global pandas and install a different version, the import fails. Always work inside the virtual env. Check with pip show pandas.

Pro tip: Use pip freeze > requirements.txt to save your package versions. Later, you can recreate the environment with pip install -r requirements.txt. This makes your project reproducible.

What you learned & what's next

You've now: - Created a virtual environment and activated it. - Installed NumPy and pandas for data using pip. - Verified the installation with a small data operation. - Learned to troubleshoot the most common installation errors. - Compared pip with conda and decided when to use which.

This is the foundation you'll build on next. In the following lesson, you'll load a real CSV file into pandas and start exploring data — but first make sure your environment is ready. Run python -c "import pandas" again if you're unsure. You've got this — you're officially ready for applied data work.

Practice recap

Create a new folder, set up a virtual environment, and install numpy and pandas. Then write a small script that loads a toy dataset (e.g., a Python list) into a DataFrame, computes the mean, and prints the result. If you run into any errors, re-read the troubleshooting section. You'll have this down in five minutes.

Common mistakes

  • Forgetting to activate the virtual environment before installing or running Python — the package installs into the global site-packages and the import fails.
  • Using sudo pip install pandas — this installs into a system directory that may not be writable and can break your global Python.
  • Installing in one terminal and coding in another without re-activating the environment — each shell needs its own activation.
  • Ignoring the Python version — some pandas versions require Python 3.9+ and fail with older Pythons.

Variations

  1. Use python -m pip install numpy pandas instead of pip install to avoid PATH issues.
  2. Use conda create -n myenv python=3.10 numpy pandas for a data-science-specific environment with precompiled binaries.
  3. Use a requirements.txt file with pinned versions for reproducible team projects.

Real-world use cases

  • A data analyst sets up a fresh Linux server to run a pandas-based ETL pipeline, using a virtual environment.
  • A machine learning engineer creates a conda environment to ensure NumPy is built with the right BLAS for Deep Learning.
  • A student follows a tutorial to install pandas and numpy for a class assignment, avoiding version conflicts with their global Python.

Key takeaways

  • Always use a virtual environment to isolate project dependencies.
  • The command pip install numpy pandas works from any terminal after activation.
  • Verify with a quick import and version check to confirm the installation.
  • If import fails, check which Python you are using—your editor or shell may differ.
  • Use pip freeze to record versions for reproducibility.

Sponsored

Sponsored

Discussion

Questions, corrections, and tips help everyone reading this page.

0 comments

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters

No comments yet — start the thread.

Related tutorials, quizzes, and articles for this topic.