How to Install 'imutils' and Fix 'ModuleNotFoundError: No module named 'imutils'" in Python
How to properly install the imutils Python package for OpenCV image processing and resolve the ModuleNotFoundError by checking your Python environment and IDE settings.
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.
pip install imutilspip3 install imutilspython -m pip install imutilspython3 -m pip install imutilspy -m pip install imutils # Windows Python Launcherpip install imutils --user # Installs to user site-packagessudo 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)
Open Command Prompt (type cmd in search) or PowerShell.
Run:
pip install imutils
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)
Open your Terminal application.
Run:
pip3 install imutils # Usually best for Python 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)
Open the integrated terminal (Ctrl+` or View -> Terminal).
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.
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:
Go to File -> Settings (or PyCharm -> Preferences).
Navigate to Project: [Your_Project_Name] -> Python Interpreter.
Click the + icon.
Search for imutils.
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.
Open Anaconda Prompt or your terminal with Conda in PATH.
Activate your target environment: conda activate your_env_name
Install using conda (preferred if available) or pip:
conda install -c conda-forge 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):
!pip install imutils
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 Virtual Environments (Highly Recommended)
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.
Create (in your project folder):
python3 -m venv venv # Or use 'python' or 'py'
Activate:
source venv/bin/activate
Install imutils (and other dependencies like OpenCV):
pip install --upgrade pip # Good practicepip install opencv-python # imutils often used with OpenCVpip 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 --versionpip --version
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.
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.