Fixing “ModuleNotFoundError” when calling Pandas or Seaborn in a cell

The error “ModuleNotFoundError: No module named ‘…'” occurs inside an Excel =PY() cell when Python attempts to import a package that is either misspelled, uninstalled, or not supported by Microsoft’s cloud environment.

While core data science libraries such as pandas, NumPy, and Seaborn are pre-installed in Excel’s default Anaconda runtime, you cannot run pip install or load arbitrary packages from PyPI. If you receive this error when importing standard libraries, the cause is typically case-sensitivity mistakes, execution order conflicts, or network policy limitations.

How to Fix ModuleNotFoundError for Pandas and Seaborn in Excel

To resolve ModuleNotFoundError, check that your import statements use all lowercase letters (import pandas as pd, import seaborn as sns). Core packages are pre-loaded by Anaconda; if the module fails to load across all cells, verify that your workbook calculation order is set to top-to-bottom, or re-initialize the import statement in the topmost Python cell of the worksheet.


The Standard Anaconda Runtime in Excel

Python in Excel runs within an isolated Microsoft Azure container running an Anaconda-curated distribution.

Pre-Installed Core Libraries

You do not need to install the following packages; they are available by default:

  • pandas (Data manipulation)
  • numpy (Matrix and mathematical arrays)
  • seaborn (Statistical charting)
  • matplotlib (Plotting and visualization)
  • scipy (Advanced mathematics and statistics)
  • statsmodels (Econometrics and regression modeling)
  • scikit-learn (Machine learning algorithms)
Supported Import:                          Unsupported Import:
import pandas as pd     [OK]                pip install my-package  [FAIL: Syntax/Error]
import seaborn as sns   [OK]                import custom_internal  [FAIL: ModuleNotFoundError]

If you attempt to import private corporate packages, legacy automation libraries, or packages outside the Anaconda standard distribution, Excel will return ModuleNotFoundError. For technical limits regarding custom libraries, read Handling “ImportError”: Why you can’t install custom pip packages in native Excel..


Step 1: Correct Casing and Import Syntax

Python is strictly case-sensitive. In Excel formulas, users often capitalize function names (e.g., =SUM(), =VLOOKUP()), and carry that habit into Python code.

Incorrect Syntax (Triggers ModuleNotFoundError)

# FAILS: Capitalized package names
import Pandas as pd
import Seaborn as sns

Correct Syntax

# WORKS: Strictly lowercase
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Ensure you do not append trailing punctuation, quotes, or semicolons outside string definitions, which can trigger Fixing “SyntaxError: invalid syntax” in the Excel Formula Bar Python editor..


Step 2: Resolve Calculation Order Dependencies

Excel Python executes cells in a specific topological sequence: Top-to-Bottom, Left-to-Right.

If you define a custom alias or import a module in cell D20, and then attempt to call that module in cell B5, Excel runs cell B5 first. Because the import has not executed yet in the container’s execution chain, the cell throws an error.

Cell B5:  sns.scatterplot(x=df['A'], y=df['B'])  <── Fails: 'sns' not recognized
...
Cell D20: import seaborn as sns                  <── Executed too late!

Best Practice Setup:

Place all library imports and initial configuration settings in a dedicated setup cell in the upper-left corner of your worksheet (e.g., cell A1):

# Cell A1: Global Configuration Block
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Every downstream Python cell on that sheet will now share that initialized namespace without error. If variables or DataFrames are missing in downstream cells, see Troubleshooting “NameError: name ‘df’ is not defined” (Cell execution order)..


Step 3: Handling Submodule Imports

Certain packages organize advanced functionality inside submodules that are not automatically loaded when you import the top-level package name.

For instance, calling scipy.stats directly after only running import scipy can trigger a module attribute error:

# Can cause runtime errors depending on container version:
import scipy
result = scipy.stats.norm.cdf(1.96)

# The correct, robust syntax:
from scipy import stats
result = stats.norm.cdf(1.96)

Similarly, if you use Seaborn to generate plots that output to the grid as images, verify your plot rendering settings using Fixing “Matplotlib” rendering errors: Why your plots aren’t showing as “Image” objects.. If the runtime environment throws internal execution breaks on supported functions, check your environment version using Troubleshooting “RuntimeError” when using unsupported library versions..