Python ModuleNotFoundError But Module Is Installed

In this article, we will see how to solve the error ModuleNotFoundError even if you have installed the module

There are several reasons why this may happen, let’s look at each one of them below.

Reason#1: Module Name is Incorrect

The Python modules are usually acronyms or code names or shortened versions of their full names, so there is a chance that you did not enter the name correctly.

For example, if I write import panda instead of import pandas (note the missing s in the end) you would still run into ModuleNotFoundError as shown below

This can also happen if you don’t have some “capitalization issue” as everything is case-sensitive in the programming world!

For example in the code below, I have the spelling correct, but I used “P” instead of “p”

import Pandas

This will also result in ModuleNotFoundError as shown below

Double-check if you have imported your module with the right spelling and you should be good to go!

Reason#2: Incorrect Python Environment Usage

This one is for advanced programmers out there who use virtual environments for development!

If you have multiple environments set up in your system, you may be using the wrong environment where the module may not exist. 

Check if you are using the correct environment and then verify if the environment you are using has the module installed!

Reason#3: Your project’s root directory is not appended to the Python PATH

Whenever you run a Python program in any environment, ensure that the environment’s directory is appended to Python PATH.

If it is not appended, then it will simply trigger a ModuleNotFoundError!

I hope by now you got the code up and running again! If not check out our full troubleshooting guide below.

ModuleNotFoundError: A Step By Step Troubleshooting Guide!

For the next step in your Python journey I invite you to master some of the most common errors you will run into in your daily life as a Python developer. We have compiled a list of just 7 exceptions that you need to focus on if you wish to gain mastery of Exceptions in Python!

7 Most Common In-Built Exceptions in Python!

If you are a visual learner here is a YouTube video that we made on that same topic!

And with that, I end this article.

I hope you enjoyed reading this article and found it useful!

Feel free to share it with your friends and colleagues!

If your thirst for knowledge has not been quenched yet, here are some related articles that might spark your interest!

Related Articles

7 Most Common In-Built Exceptions in Python!

Python Exceptions: Explained for Beginners!

Python: When To Use Custom Exceptions? Explained!

Python TypeError: A Step By Step Troubleshooting Guide!

Thanks to Namazi Jamal for his contributions in writing this article!

Photo of author
Balaji Gunasekaran
Balaji Gunasekaran is a Senior Software Engineer with a Master of Science degree in Mechatronics and a bachelor’s degree in Electrical and Electronics Engineering. He loves to write about tech and has written more than 300 articles. He has also published the book “Cracking the Embedded Software Engineering Interview”. You can follow him on LinkedIn