Skip to main content

Python PyCaret: How to Resolve Import Errors from PyCaret in Python

PyCaret is a powerful, low-code machine learning library that simplifies end-to-end ML workflows in Python. However, getting it installed and running smoothly can be surprisingly tricky - import errors are one of the most frequently reported issues. These errors can stem from dependency conflicts, incorrect installations, Python version mismatches, or environment problems.

In this guide, we'll walk through the common causes of PyCaret import errors, show you real error examples, and provide step-by-step solutions to get PyCaret working correctly.

What Does a PyCaret Import Error Look Like?

PyCaret import errors can manifest in several ways depending on the root cause:

from pycaret.classification import setup

Possible error outputs:

ModuleNotFoundError: No module named 'pycaret'
ImportError: cannot import name 'setup' from 'pycaret.classification'
ImportError: DLL load failed while importing _arpack: The specified module could not be found.
ModuleNotFoundError: No module named 'sklearn'

Each of these points to a different underlying issue. Let's address them systematically.

Common Causes and Solutions

1. PyCaret Is Not Installed or Is Installed Incorrectly

The most basic cause is that PyCaret simply isn't installed in your current Python environment.

Verify the installation:

pip show pycaret

If nothing is returned, PyCaret isn't installed. Install it with:

pip install pycaret

For the full installation (including all optional dependencies for NLP, anomaly detection, etc.):

pip install pycaret[full]

If PyCaret is already installed but you're still seeing errors, try a clean reinstall:

pip uninstall pycaret -y
pip install pycaret
tip

Always verify the installation after installing:

import pycaret
print(pycaret.__version__)

Expected output:

3.3.2

2. Python Version Incompatibility

PyCaret has specific Python version requirements that change between releases. Using an unsupported Python version is a frequent source of import failures.

Check your Python version:

python --version

PyCaret version compatibility:

PyCaret VersionSupported Python Versions
PyCaret 2.xPython 3.6 – 3.8
PyCaret 3.xPython 3.8 – 3.11
caution

PyCaret 3.x does not support Python 3.12+ as of this writing due to dependency constraints. If you're on Python 3.12 or later, you may need to use an older Python version in a virtual environment. Always check the official PyCaret documentation for the latest compatibility information.

Fix - Create a virtual environment with a compatible Python version:

# Using conda
conda create -n pycaret_env python=3.10
conda activate pycaret_env
pip install pycaret

# Using venv (if you have Python 3.10 installed)
python3.10 -m venv pycaret_env
source pycaret_env/bin/activate # Linux/macOS
pycaret_env\Scripts\activate # Windows
pip install pycaret

3. Dependency Conflicts

PyCaret depends on a large number of packages (scikit-learn, pandas, numpy, lightgbm, and many more). Version conflicts between these dependencies are the most common cause of import errors.

❌ Typical error from a dependency conflict

from pycaret.classification import setup
ImportError: cannot import name 'MaskedArray' from 'numpy.ma.core'

or:

AttributeError: module 'sklearn.utils' has no attribute '_safe_indexing'

These errors occur when PyCaret expects a specific version of a dependency but a different version is installed.

Fix: Use a fresh virtual environment

The most reliable approach is to install PyCaret in an isolated virtual environment so its dependencies don't conflict with other packages:

# Create a clean environment
python -m venv pycaret_env
source pycaret_env/bin/activate # Linux/macOS
pycaret_env\Scripts\activate # Windows

# Install PyCaret fresh
pip install pycaret

Fix: Force reinstall all dependencies

If you can't create a new environment, force-reinstall PyCaret with all its dependencies:

pip install pycaret --force-reinstall

Fix: Install specific dependency versions manually

If you identify the conflicting package, you can pin it to the version PyCaret expects:

# Example: PyCaret might need a specific scikit-learn version
pip install scikit-learn==1.2.2

4. Importing from the Wrong PyCaret Version (2.x vs 3.x)

PyCaret 3.x introduced significant API changes compared to 2.x. Code written for PyCaret 2.x won't work with PyCaret 3.x and vice versa.

❌ Wrong: PyCaret 2.x syntax on PyCaret 3.x

from pycaret.classification import setup, compare_models

# PyCaret 2.x style
clf = setup(data=df, target='target', session_id=123)

In PyCaret 3.x, the setup() function returns an experiment object and some parameter names have changed.

✅ Correct: PyCaret 3.x syntax
from pycaret.classification import ClassificationExperiment

# PyCaret 3.x style
exp = ClassificationExperiment()
exp.setup(data=df, target='target', session_id=123)
best_model = exp.compare_models()
info

PyCaret 3.x also supports the functional API for backward compatibility, but some parameter names and behaviors have changed. Check the migration guide when upgrading.

5. Jupyter Notebook Kernel Issues

If PyCaret installs successfully in your terminal but fails to import in Jupyter Notebook, the notebook kernel may be using a different Python environment.

Diagnose the issue:

# Run this in a Jupyter cell
import sys
print(sys.executable)
print(sys.version)

Compare the output with what you see when you run python --version and which python in your terminal. If they differ, the notebook is using a different Python installation.

Fix: Install PyCaret in the notebook's environment

# Run directly in a Jupyter cell
!pip install pycaret

Fix: Register your virtual environment as a Jupyter kernel

# Activate your virtual environment first
pip install ipykernel
python -m ipykernel install --user --name=pycaret_env --display-name="PyCaret Env"

Then select "PyCaret Env" as the kernel in Jupyter.

6. Platform-Specific Issues (Windows DLL Errors)

On Windows, you may encounter DLL-related import errors:

ImportError: DLL load failed while importing _arpack: The specified module could not be found.

This typically means that compiled dependencies like scipy or numpy are missing required C++ runtime libraries.

Fix: Install the Microsoft Visual C++ Redistributable

Download and install the latest Microsoft Visual C++ Redistributable for your system.

Fix: Use conda instead of pip

Conda handles compiled dependencies and their system-level requirements better than pip on Windows:

conda create -n pycaret_env python=3.10
conda activate pycaret_env
conda install -c conda-forge pycaret

Step-by-Step Debugging Checklist

When you encounter a PyCaret import error, work through this checklist:

# 1. Check Python version
python --version

# 2. Check if PyCaret is installed
pip show pycaret

# 3. Check for dependency conflicts
pip check

# 4. List all installed packages and their versions
pip list

# 5. Try importing with verbose error output
python -c "from pycaret.classification import setup"

# 6. Check which Python executable is being used
python -c "import sys; print(sys.executable)"

The pip check command is especially useful - it reports any dependency conflicts in your environment:

$ pip check

Example output with conflicts:

scikit-learn 1.4.0 has requirement numpy>=1.19.5, but you have numpy 1.18.0.

Quick Reference: Solutions Summary

ProblemSolution
ModuleNotFoundError: No module named 'pycaret'pip install pycaret
Dependency conflictsInstall in a fresh virtual environment
Python version incompatibilityUse Python 3.8–3.11 with PyCaret 3.x
API changes (2.x vs 3.x)Update code to PyCaret 3.x syntax
Jupyter kernel mismatchInstall ipykernel and register the correct environment
Windows DLL errorsInstall Visual C++ Redistributable or use conda
Persistent issuespip install pycaret --force-reinstall in a clean venv

Conclusion

PyCaret import errors almost always come down to one of three things: Python version incompatibility, dependency conflicts, or environment mismatches.

The most reliable way to avoid these issues is to install PyCaret in a clean virtual environment with a supported Python version (3.8–3.11 for PyCaret 3.x).

If you're upgrading from PyCaret 2.x, be aware that the API has changed significantly, review your import statements and function calls against the latest documentation.

When all else fails, a pip install pycaret --force-reinstall in a fresh environment resolves the vast majority of cases.