“Module not found” error in Python :

Parth Gajmal
2 min readMay 8, 2023

--

If you encounter a “Module not found” error while running a Python file in the CMD (Command Prompt), it typically means that the required module is not installed or not accessible to the Python interpreter. Here are a few steps you can take to resolve this issue:

https://youtu.be/r9m4I-foa-E

Check module installation: Make sure the module you are trying to import is installed on your system. You can use the pip package manager to install missing modules. Open a CMD window and run the following command:

pip install module_name

Replace module_name with the actual name of the module you are missing. If the module is already installed, you might need to update it using:

pip install --upgrade module_name

Confirm Python version: Ensure that you are using the correct Python version. Sometimes, you may have multiple versions of Python installed, and the module might be installed for a different version. Check your Python version by running:

python --version

Virtual environments: If you are using virtual environments, ensure that you have activated the correct environment. Activate the virtual environment before running your script. In the CMD, navigate to the project directory and run the activation command specific to your virtual environment. For example:

myenv\Scripts\activate

conda activate base - then run your file e.g. python main.py

Check PYTHONPATH: The PYTHONPATH environment variable contains a list of directories where Python looks for modules. Ensure that the module you are trying to import is located in one of the directories listed in PYTHONPATH.

Module location: If the module you are trying to import is not installed using pip but is available as a standalone package, make sure the module is located in the same directory as your Python script. The Python interpreter looks for modules in the current working directory by default.

Syntax errors: Sometimes, a syntax error or an incorrect import statement within your Python script can cause the “Module not found” error. Double-check your code for any syntax issues or typos in the import statements.

By following these steps, you should be able to resolve most “Module not found” errors in the CMD and successfully run your Python file.

--

--

Parth Gajmal

Data scientist sharing insights on Medium to empower others in analytics and machine learning. Passionate about driving impactful solutions.