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.
As I have already mentioned we will address this section with pip, conda, and source code.
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 –
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
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
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
Thanks
Data Science Learner Team