Modulenotfounderror no module named X error occurs if respective module [X] is either not installed or its path is not set properly. Here [X] can be any python module like Flask, Pandas, etc. Typically we fix this error by installing or reinstalling the package. Mostly we install any python package either via pip, conda, or source code. There are some other methods like easy_install etc but most developers prefer pip, conda, or source code.
We have designed this article to give you a generic solution for Modulenotfounderror. At the end of this article, we will add multiple module-specific examples.
Modulenotfounderror no module named X : ( Fix ) –
As I have already mentioned we will address this section with pip, conda, and source code.
Solution 1: modulenotfounderror fixing with pip –
pip is the most popular python package manager. With pip, we can install any python package with a single command. pip has the capability to install any package from any of the sources –
- PyPI Hub or similar Indexing Hub.
- Local or remote archives.
- Local directories.
- VCS project URLs.
Here is the command which you can use to install any python package.
pip install python-package
Here you can replace the python-package with your own package. Also, make sure that it will install the latest version of the provided package. If you want to make this version specific, you can provide the version as well.
pip install python-package==version
Solution 2: modulenotfounderror fixing with conda –
Just similar to pip, we can leverage conda manager which comes by default with the Anaconda package. Here we can run the below command.
conda install python-package
Solution 3: modulenotfounderror fixing with SETUP.PY-
Typically when we package any python module. We create setup.py file to install it. So basically we need to download the source code and then install the dependencies and run the below command.
python setup.py install
Module specific similar Errors –
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.