dbt python model failed: pandas not installed
Fixes missing pandas in dbt python model environments for analytics engineers and repair agents. Use when a python model fails because pandas is not installed. Not for pandas version conflicts or code bugs in the model.
TL;DR
The python environment running the model lacks pandas. Install it into the right environment (the warehouse's python env for Snowpark/Databricks, or your local env for local runs), pin the version your code needs, and re-run the model.
Error
dbt python model failed: pandas not installedSteps
Find which environment runs the python model: Snowflake Snowpark, Databricks, BigQuery DataFrames, or local. The error tells you where the import failed. Expected: You know the target environment, e.g. a Snowpark session.
Install pandas there: for Snowpark use packages in the model config or session.add_packages; for Databricks install on the cluster; locally pip install pandas. Expected: pandas importable in that environment.
Pin a version compatible with the environment (Snowpark ships specific pandas builds; Databricks runtime pins its own). Expected: A version pin that matches the platform, not just latest.
Re-run dbt run --select thepythonmodel. Expected: The model imports pandas and builds.
When to use
- python model fails with pandas not installed or No module named pandas
- new python model on an environment that never had pandas
- after switching the python environment or warehouse
When not to use
- pandas is installed but the version conflicts (that is a version pin problem)
- the model code itself errors (that is a code bug, not the install)
- a SQL model failing (pandas is irrelevant there)
Tool compatibility
- dbt python models (1.3+); Snowpark, Databricks, BigQuery backends
- session.add_packages or model packages config for Snowpark
- pip for local python environments
Variant phrasings
pandas not installed on Snowpark
Use the packages config on the model: {{ config(packages=['pandas==2.0.3']) }} with a Snowpark-compatible version.
pandas missing only in CI
CI uses a different python env than your laptop. Install into the CI env or container image.
Why it happens
dbt python models run inside the warehouse's python runtime, not your laptop's. That runtime starts minimal; pandas is not guaranteed. The import fails at model runtime because nobody installed it where the code actually executes.
Edge cases
- Snowpark's Anaconda channel lags PyPI; pin versions it actually carries or the install fails differently.
- Large pandas versions on small warehouses can OOM the python worker; keep the model lean.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_v9jKxBQRceZjiFfzZSzhxQ