ModuleNotFoundError
ModuleNotFoundError: No module named 'requests'
Traceback
Traceback (most recent call last):
File "main.py", line 1, in <module>
import reqeusts # typo
ModuleNotFoundError: No module named 'requests'What causes this error
The module does not exist on any path in sys.path. It either is not installed, is misspelled, is installed in a different virtual environment, or is shadowed by a local file with the same name.
How to fix it
Install the module with `pip install module_name`. Ensure you are using the correct virtual environment. Check for local files that might shadow the module name. Verify the module name spelling.
Code that causes this error
import reqeusts # typo
Fixed code
import requests # correct name, after: pip install requests
About ModuleNotFoundError
A ModuleNotFoundError (a subclass of ImportError, introduced in Python 3.6) is raised when Python cannot locate the module you are trying to import. This means the module is not installed in the current environment, is not in any directory on `sys.path`, or the module name is misspelled. This is distinct from ImportError in that it specifically means the module itself was not found at all, rather than a name within a found module.
The most common scenario is forgetting to install a third-party package with pip before importing it, or running the script in a different virtual environment than the one where packages are installed. Other causes include naming your own script the same as a standard library module (shadowing), a missing `__init__.py` in a package directory (in Python 3 with regular packages), and incorrect `PYTHONPATH` configuration.
Common scenarios
Installing packages in a different virtual environment than the one in use
Circular imports between modules that depend on each other
Typos in module or package names in import statements
Naming a local file the same as a standard library module