Skip to content

Q&A · Answered

How to fix ModuleNotFoundError: No module named in Python

asked 9 months, 1 week ago 2272 views 1 answer
45

I installed a package with pip but Python says "ModuleNotFoundError: No module named". I've tried reinstalling but it still doesn't work.

1 Answer

One accepted
12

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

This is a common issue usually related to Python environments. Here are the solutions:

Check which Python is being used

# Check Python path
which python
which python3
# Check pip path
which pip
which pip3

Install to correct Python

# Use python -m pip to ensure correct pip
python3 -m pip install package-name
# Or specify full path
/usr/bin/python3 -m pip install package-name

Virtual environment solution

# Create and use virtual environment
python3 -m venv venv
source venv/bin/activate
pip install package-name

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.