Skip to main content

How to Solve "ModuleNotFoundError: No module named 'tqdm'" in Python

The error ModuleNotFoundError: No module named 'tqdm' in Python means the tqdm library (used for progress bars) is not installed in the Python environment you're using.

This guide provides a complete guide to installing tqdm and resolving this common error.

Understanding the Error

The ModuleNotFoundError indicates that when your code uses import tqdm (or from tqdm import ...), Python can't find a module named tqdm. This almost always means tqdm is not installed, or is not installed in the correct environment.

pip is Python's package installer. Use it to install tqdm:

Basic Installation

Open your terminal (or command prompt/PowerShell on Windows) and run:

pip install tqdm

If you have multiple Python versions or pip refers to Python 2, use:

pip3 install tqdm # Use pip3 for python 3

Using python -m pip (If pip Isn't in Your PATH)

If pip isn't found, use:

python -m pip install tqdm  # Use with your system's default Python
python3 -m pip install tqdm # Use with your system's python3

Windows-Specific Considerations (py launcher)

On Windows, use the py launcher:

py -m pip install tqdm
  • The command py will execute using the latest version of Python.

Permissions Issues (sudo or --user)

On Linux/macOS, you might need sudo for system-wide installation (virtual environments are strongly preferred):

sudo pip3 install tqdm # System wide
  • The sudo command gives you administrator privileges, and might be needed to install packages in the system.

Or, install into your user's site-packages:

pip install tqdm --user  # Install for current user only
  • The --user argument installs the package for the current user.

Always use virtual environments for Python projects:

Creating a Virtual Environment

python3 -m venv venv  # Create an environment named "venv"
# OR: python -m venv venv
# OR: py -m venv venv (Windows)

Activating the Environment

  • macOS / Linux:

    source venv/bin/activate
  • Windows (Command Prompt):

    venv\Scripts\activate.bat
  • Windows (PowerShell):

    venv\Scripts\Activate.ps1

    You may also need to set the execution policy:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Your prompt will change (e.g., (venv)). pip install now installs only into this environment.

Installing tqdm Inside the Environment

With the environment activated:

pip install tqdm

Troubleshooting

If you still get the error:

  • IDE Configuration (VS Code, PyCharm): Your IDE might use a different interpreter.
    • VS Code: Ctrl+Shift+P (or Cmd+Shift+P on macOS), "Python: Select Interpreter," choose your virtual environment.
    • PyCharm: File > Settings > Project > Python Interpreter (or PyCharm > Preferences > Project > Python Interpreter on macOS), select your environment.
  • Conflicting Installations/Multiple Python Versions: If you have multiple Python versions without virtual environments, you might have installed tqdm for the wrong one. Always use virtual environments.
  • Incorrect Filenames/Variable Names: Never name your files tqdm.py. Don't create a variable called tqdm before importing.
  • Restarting Your IDE/Kernel: Sometimes a restart is needed.
  • Reinstalling:
    pip uninstall tqdm
    pip install tqdm

Using tqdm (Example)

The example code shows how to use tqdm to display a progress bar.

from time import sleep
from tqdm import tqdm # Import tqdm

text = ""
for char in tqdm(["a", "b", "c", "d"]):
sleep(0.25) # Sleep to simulate work.
text = text + char
print(text)

Installing tqdm in Specific Environments

  • Anaconda:

    conda install -c conda-forge tqdm
  • Jupyter Notebook:

    !pip install tqdm