How to Fix: ModuleNotFoundError: No module named ‘pandas’

3D illustration of a missing library book representing the ModuleNotFoundError for Pandas in Python.

You’re excited to start your first data science project, you type import pandas as pd, run your script, and… crash. The error message reads ModuleNotFoundError: pandas, leaving you baffled.

ModuleNotFoundError: No module named 'pandas'

Don’t panic. Errors like ModuleNotFoundError: pandas are among the easiest to fix. It just means Python can’t find the Pandas library on your computer.

Cause 1: You Haven’t Installed It Yet (Most Common)

Python does not come with Pandas pre-installed. You must install it yourself using pip, Python’s package manager.

The Fix: Open your terminal or command prompt and run:

pip install pandas

(Mac/Linux users might need pip3 install pandas or python3 -m pip install pandas).

Wait for the installation to finish, then try running your script again. This should resolve your ModuleNotFoundError: pandas issue if it wasn’t installed.

Cause 2: You’re in the Wrong Environment

If you know you installed it, but it still fails, you are likely using the wrong Virtual Environment or Python interpreter.

You might have installed Pandas globally, but your IDE (like VS Code or PyCharm) is actively running inside a new virtual environment where it’s not installed yet.

The Fix:

  1. Check your IDE’s bottom status bar to see which Python interpreter is selected.
  2. Make sure you activated your virtual environment in the terminal before running pip install pandas. Otherwise, you might face the ModuleNotFoundError: pandas.

Cause 3: Multiple Python Versions Confusion

You might have Python 3.10 and Python 3.12 both installed. You installed pandas for 3.10, but you are running your script with 3.12.

The Fix: Instead of just pip install pandas, try being specific about which Python you are using:

# Installs for the specific 'python' currently active
python -m pip install pandas

This is often safer than just typing pip to avoid the ModuleNotFoundError: pandas when running scripts with different versions.

Summary

99% of the time, this error just means you forgot to run pip install pandas. Do that first to tackle ModuleNotFoundError: pandas!

Similar Posts

Leave a Reply