Skip to content

How to Fix "No Module Named Pandas" Error in Python

Published on

Updated on

ModuleNotFoundError: No module named 'pandas' means Python cannot find the pandas package in the environment you are currently running. Almost always, pandas is installed somewhere — just not in the interpreter or kernel that ran your code. The fix is to install pandas into that exact environment, or point your tool at the environment where it already lives.

This guide gives you the quick fix first, then walks through every cause — interpreter mismatch, virtual environments, Jupyter kernels, IDE settings, and naming conflicts — with copy-paste commands.

Quick fix

Run these in order — the first one resolves it for most people:

# Install into the SAME Python you run (most reliable)
python -m pip install pandas

If you are in a Jupyter notebook (the most common cause in data science), install into the running kernel, then restart it:

%pip install pandas
# After it finishes: Kernel > Restart, then re-run your import

Confirm which Python is actually executing your code:

import sys
print(sys.executable)   # this is the interpreter pip must install into

And make sure no local file is shadowing the library — a file named pandas.py in your folder will hijack the import:

# From your project directory
ls pandas.py        # if this exists, rename it and delete __pycache__

Still stuck? Keep reading — the cause-by-cause sections below cover every remaining scenario.

Causes & solutions

CauseFix
Pandas not installedpython -m pip install pandas (or conda install pandas)
Wrong interpreter / multiple PythonsInstall with python -m pip install pandas so pip targets the Python you run
Virtual environment not activatedActivate the venv first, then install/run
Jupyter kernel mismatch%pip install pandas inside the notebook, then restart the kernel
IDE points at wrong interpreterSelect the correct interpreter in VS Code / PyCharm
Local pandas.py or stale __pycache__Rename your file and delete __pycache__/
Corrupted / partial installpip install pandas --no-cache-dir after uninstalling

Issue 1: Pandas is not installed

The simplest case — pandas just isn't in the current environment. Check, then install:

pip show pandas        # returns version info if installed; nothing if not
python -m pip install pandas
# conda users:
conda install pandas

Verify it imports:

import pandas as pd
print(pd.__version__)

If the import works, you're done. If it still fails, the package is installed somewhere your code can't reach — that's the rest of this guide.

Issue 2: Multiple Python versions or wrong interpreter

This is the #1 real-world cause. You install pandas, but python script.py runs a different Python than the pip you used. For example, pandas lands in Python 3.11 while your script runs Python 3.9.

Check what you actually have:

python -V
python3 -V
pip --version    # shows which Python this pip belongs to

The reliable fix is to bind pip to the interpreter you run, using python -m pip:

python -m pip install pandas

On Windows, target a specific version explicitly with the launcher:

py -3.11 -m pip install pandas

This guarantees pandas installs into the same interpreter that runs your code.

Issue 3: Virtual environment not activated

If you created a virtual environment but forgot to activate it, you install (or run) against the wrong Python. Activate the venv first:

# macOS / Linux
source venv/bin/activate
 
# Windows (PowerShell / cmd)
.\venv\Scripts\activate

Then install inside the activated environment:

pip install pandas

Confirm Python now points at the venv:

import sys; print(sys.executable)   # should be inside your venv folder

Remember: a pandas install is scoped to the active environment only.

Issue 4: Jupyter kernel mismatch

The most frequent cause in data-science workflows. You pip install pandas in the terminal, but your notebook's kernel is a completely different Python, so the import fails inside Jupyter even though the terminal works.

First, see which Python the notebook is using:

import sys; print(sys.executable)

Then install into that running kernel with the %pip magic and restart:

%pip install pandas
# Then: Kernel > Restart, and re-run the import

If you want a specific environment to appear as a selectable kernel, register it:

python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

After registering, pick "Python (myenv)" from the kernel selector so the notebook uses the environment where pandas lives.

Issue 5: IDE using the wrong interpreter (VS Code / PyCharm)

If your editor is configured to a different environment, pandas looks "missing" even though it's installed.

VS Code — open the Command Palette and pick the right environment:

Ctrl + Shift + P  →  "Python: Select Interpreter"

Then choose the interpreter (venv/conda) where pandas is installed. The selected interpreter also shows in the bottom-right status bar.

PyCharm — go to Settings/Preferences → Project → Python Interpreter, and select the environment that has pandas (or add it).

Issue 6: Naming conflict (local pandas.py / pycache)

If your project contains a file named pandas.py or a folder named pandas/, Python imports your file instead of the real library — and you'll see the No module named error or strange attribute errors.

Rename the offending file to something neutral and remove any cached bytecode:

mv pandas.py my_pandas_test.py
rm -rf __pycache__/

Stale __pycache__ directories can keep serving the old shadowed module even after you rename, so deleting them is part of the fix.

Issue 7: Corrupted or partial install

If an install was interrupted or a dependency failed, pandas can be half-installed and import in a broken state. Do a clean reinstall, bypassing the cache:

pip uninstall pandas
pip install pandas --no-cache-dir

Then check that nothing is left with broken dependencies:

pip check

Summary

SymptomMost likely causeCommand to run
Fresh environment, never installedNot installedpython -m pip install pandas
Works in terminal, fails in scriptWrong interpreterpython -m pip install pandas
Works in terminal, fails in notebookKernel mismatch%pip install pandas + restart kernel
Works on CLI, fails in editorIDE interpreterSelect correct interpreter in VS Code / PyCharm
Import grabs the wrong thingLocal pandas.pyRename file, delete __pycache__/
Installed but import errors outCorrupted installpip install pandas --no-cache-dir

Alternative: explore your data without the setup — PyGWalker

Once pandas imports cleanly, the next hurdle is usually visualizing the DataFrame. PyGWalker is an open-source library that turns a pandas (or Polars) DataFrame into a Tableau-style drag-and-drop interface right inside Jupyter — no plotting boilerplate needed.

pip install pygwalker
import pygwalker as pyg
gwalker = pyg.walk(df)

It runs in Jupyter Notebook, JupyterLab, Kaggle, and Google Colab. If you like it, a ⭐️ on GitHub (opens in a new tab) is appreciated.

FAQ

I installed pandas but still get the error — why?

You are almost certainly running a different Python interpreter than the one where pandas was installed. Run import sys; print(sys.executable) to see the active interpreter, then install with python -m pip install pandas so pip targets that exact Python.

Why does it fail only in Jupyter?

Your notebook kernel is a different environment from your terminal. Install into the running kernel with %pip install pandas and restart the kernel.

Why does the error persist after reinstalling?

The install may be corrupted, or a local pandas.py file is shadowing the library. Reinstall with pip install pandas --no-cache-dir, and make sure no file named pandas.py sits in your working directory.

Should I use pip or conda?

Use whichever manages the environment you run your code in. If you created the environment with conda, prefer conda install pandas; otherwise python -m pip install pandas is the safe default.

Related Guides

📚