Skip to main content

How to Install "imutils" and Fix "ModuleNotFoundError: No module named 'imutils'" in Python

imutils is a popular Python package providing a series of convenience functions to make basic image processing tasks with OpenCV easier, such as translation, rotation, resizing, and displaying Matplotlib images. If you try to import imutils in your Python script without first installing it, or if it's installed in a different Python environment than the one your script is using, you'll encounter the ModuleNotFoundError: No module named 'imutils'.

This guide provides comprehensive instructions on how to correctly install imutils across various platforms and IDEs, and how to troubleshoot the ModuleNotFoundError.

What is imutils?

The imutils package, created by Adrian Rosebrock of PyImageSearch, offers a collection of utility functions that simplify common image processing operations when working with OpenCV. These include functions for resizing, rotation, skeletonization, URL to image conversion, and more, making image manipulation tasks more convenient.

Solving ModuleNotFoundError: No module named 'imutils'

This error means Python cannot find the imutils package in its current search path.

Cause: Package Not Installed or Incorrect Environment**

The most common reasons are:

  • You haven't installed imutils yet.
  • You installed imutils in a different Python environment (e.g., global Python) than the one your current script or IDE is using (e.g., a virtual environment).

Solution: Install imutils using Pip (Primary Method)**

pip is Python's standard package installer. Open your terminal or command prompt. If you are using a virtual environment, ensure it is activated first.

# Standard pip install
pip install imutils

# If you use Python 3 and might have Python 2 pip on PATH:
pip3 install imutils

# To ensure you use pip associated with a specific python interpreter:
python -m pip install imutils
python3 -m pip install imutils
py -m pip install imutils # Windows Python Launcher

# If you encounter permission errors (less ideal than venvs or --user for global installs):
pip install imutils --user # Installs to user site-packages
sudo pip3 install imutils # Linux/macOS global install (use with caution)

After successful installation, your import imutils statement should work.

Platform-Specific Installation Instructions

The core command (pip install imutils) is the same, but accessing the terminal and managing Python environments can vary.

Windows (Command Prompt / PowerShell)

  1. Open Command Prompt (type cmd in search) or PowerShell.
  2. Run:
    pip install imutils
    # Or if multiple Pythons/PATH issues:
    # py -m pip install imutils
  3. For permission issues when installing globally (not recommended), consider running as Administrator or use pip install imutils --user. Virtual environments are preferred.

macOS / Linux (Terminal)

  1. Open your Terminal application.
  2. Run:
    pip3 install imutils # Usually best for Python 3
    # Or:
    # python3 -m pip install imutils
  3. For permission issues when installing globally (not recommended), use sudo pip3 install imutils or pip3 install imutils --user. Virtual environments are preferred.

Visual Studio Code (Integrated Terminal)

  1. Open the integrated terminal (Ctrl+` or View -> Terminal).
  2. Ensure the correct Python interpreter/virtual environment is selected for your workspace. VS Code often shows this in the bottom status bar. The terminal should use this environment.
  3. Run:
    pip install imutils

PyCharm (Terminal / Package Manager GUI)

  • Terminal: Open the Terminal tool window (Alt+F12). Ensure it's using your project's configured interpreter (often a venv). Run:
    pip install imutils
  • Package Manager GUI:
    1. Go to File -> Settings (or PyCharm -> Preferences).
    2. Navigate to Project: [Your_Project_Name] -> Python Interpreter.
    3. Click the + icon.
    4. Search for imutils.
    5. Select it and click "Install Package".

Anaconda / Conda Environments

While imutils might be installable via pip within a Conda environment, it's often better to use conda to install packages if available on a Conda channel (like conda-forge) to ensure better dependency management within the Conda ecosystem.

  1. Open Anaconda Prompt or your terminal with Conda in PATH.
  2. Activate your target environment: conda activate your_env_name
  3. Install using conda (preferred if available) or pip:
    # Check conda-forge first (common channel for many packages)
    conda install -c conda-forge imutils

    # If not on conda-forge or you prefer pip within conda:
    # pip install imutils

Jupyter Notebook / Lab

  • Method 1 (Install Before Starting): The best way is to install imutils in the same Python environment (terminal/command prompt) from which you launch Jupyter. Activate your venv/conda env, pip install imutils, then start jupyter notebook or jupyter lab.
  • Method 2 (Install from Notebook Cell):
    # In a code cell:
    !pip install imutils
    # OR (if using conda environment as kernel):
    # !conda install -c conda-forge imutils -y
    Important: After installing via !pip or !conda, you must restart the kernel (Kernel menu -> Restart Kernel...) for the notebook to recognize the newly installed package.

Using a virtual environment for each project is the best way to manage dependencies and avoid ModuleNotFoundError due to packages being installed in the wrong place.

  1. Create (in your project folder):
    python3 -m venv venv # Or use 'python' or 'py'
  2. Activate:
    # Linux/macOS:
    source venv/bin/activate
    # Windows CMD:
    # venv\Scripts\activate.bat
    # Windows PowerShell:
    # venv\Scripts\Activate.ps1
  3. Install imutils (and other dependencies like OpenCV):
    # Prompt shows (venv)
    pip install --upgrade pip # Good practice
    pip install opencv-python # imutils often used with OpenCV
    pip install imutils
    Now, any script run while this venv is active will find imutils.

Troubleshooting Persistent ModuleNotFoundError

If you've installed imutils but still get the error:

Verify Python Version and Pip Association

Ensure the python and pip commands you're using correspond to the same Python installation.

python --version
pip --version
# Or python3 / pip3

If you have multiple Python versions, use pythonX.Y -m pip install imutils (e.g., python3.9 -m pip install imutils) to be explicit.

Check if Package is Installed (pip show imutils)

Run this in the same terminal/environment where your script fails:

pip show imutils

If it shows "WARNING: Package(s) not found", it's not installed in that environment. If it shows details, check the Location:. Does it make sense for the environment you think you're using?

Ensure Correct Interpreter in IDE

If using an IDE (VS Code, PyCharm), double-check that the project interpreter is set to the Python executable from your virtual environment or the system Python where you installed imutils.

Avoid Filename/Variable Shadowing

  • Do not name any of your Python files imutils.py in your project.
  • Do not use imutils as a variable name before import imutils.

Reinstall the Package

Sometimes a fresh install can help:

pip uninstall imutils -y
pip install imutils --no-cache-dir # --no-cache-dir for fresh download

Conclusion

The ModuleNotFoundError: No module named 'imutils' typically means the imutils package is not installed in the Python environment your script is currently using.

The primary solution is to install imutils using pip:

pip install imutils

Crucially, ensure this installation happens within the correct, active Python environment (preferably a virtual environment). If issues persist, verify your Python/pip paths, IDE interpreter settings, and ensure no local files are shadowing the package. Using virtual environments consistently is the best defense against such import errors.