modulenotfounderror: no module named pycocotools error occurs because of incompatibility of pycocotools in various top layer packages (TensorFlow etc). Typically we have seen this error in object detection with TensorFlow at the evaluation stage. But there may be multiple scenarios where we can get this error. The motive to create this article is to provide a generic solution which will fit all such similar errors.
modulenotfounderror: no module named pycocotools ( Approaches to Fix ) –
There are multiple ways to fix this error but we will start with easiest.
Approach 1: Using pycocotools source code –
The source code for pycocotools resides in git. we will pull the code from there and install the same. But to incorporate this completely, It is advisable to upgrade the related packages ( scikit-image, cython) with it. Here is the command set you can try-
pip3 install -U scikit-image pip3 install -U cython pip3 install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"
Note – It is advisable to install Install Visual C++ 2015 Build Tools along with such similar packages
Approach 2: Installation of pycocotools with pypi using pip –
Here we will use pip package manager and pull the build from pypi repository. Here is the command for the same.
pip install pycocotools
window users can also try to execute the below command-
pip install pycocotools-windows
Approach 3: Installation of pycocotools with conda –
Just like pip, we can use conda package manager to install or upgrade pycocotools. Here is the command for the same.
conda install -c conda-forge pycocotools
we have used conda-forge mirror but there are other possibilities which you can use. Please refer to below
details for this.
These pycocotools deal with coco dataset which is generalized for object detection, image detection, and another computer vision-related task. This is mainly useful in most of the state of art algorithms in computer vision. I hope this article, will help you in fixing the above error. In case of any queries please reach out to us.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.