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 setupPossible 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 pycaretIf nothing is returned, PyCaret isn't installed. Install it with:
pip install pycaretFor 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 pycaret2. 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 --versionPyCaret version compatibility:
| PyCaret Version | Supported Python Versions |
|---|---|
| PyCaret 2.x | Python 3.6 – 3.8 |
| PyCaret 3.x | Python 3.8 – 3.11 |
Fix - Create a virtual environment with a compatible Python version:
conda create -n pycaret_env python=3.10
conda activate pycaret_env
pip install pycaret
python3.10 -m venv pycaret_env
source pycaret_env/bin/activate # Linux/macOS
pycaret_env\Scripts\activate # Windows
pip install pycaret3. 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 setupImportError: 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:
python -m venv pycaret_env
source pycaret_env/bin/activate # Linux/macOS
pycaret_env\Scripts\activate # Windows
pip install pycaretFix: Force reinstall all dependencies
If you can't create a new environment, force-reinstall PyCaret with all its dependencies:
pip install pycaret --force-reinstallFix: Install specific dependency versions manually
If you identify the conflicting package, you can pin it to the version PyCaret expects:
pip install scikit-learn==1.2.24. 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
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
exp = ClassificationExperiment()
exp.setup(data=df, target='target', session_id=123)
best_model = exp.compare_models()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:
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
!pip install pycaretFix: Register your virtual environment as a Jupyter kernel
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 pycaretStep-by-Step Debugging Checklist
When you encounter a PyCaret import error, work through this checklist:
python --version
pip show pycaret
pip check
pip list
python -c "from pycaret.classification import setup"
python -c "import sys; print(sys.executable)"The pip check command is especially useful - it reports any dependency conflicts in your environment:
$ pip checkExample 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
| Problem | Solution |
|---|---|
ModuleNotFoundError: No module named 'pycaret' |
pip install pycaret |
| Dependency conflicts | Install in a fresh virtual environment |
| Python version incompatibility | Use 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 mismatch | Install ipykernel and register the correct environment |
| Windows DLL errors | Install Visual C++ Redistributable or use conda |
| Persistent issues | pip 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.