Skip to content

ImportError: No module named 'pycocotools' #6

Closed
@Walid-Ahmed

Description

@Walid-Ahmed

Thanks a lot
I am having the following error
"ImportError: No module named 'pycocotools'"

Can you please advice me how to install it as I could not find it on pip or conda?

I tried the installation from https://github.com/cocodataset/cocoapi but did not work too

Activity

Walid-Ahmed

Walid-Ahmed commented on Nov 2, 2017

@Walid-Ahmed
Author
hi-mel

hi-mel commented on Nov 2, 2017

@hi-mel

Cloning https://github.com/waleedka/coco (which is @waleedka's fork of the coco API), then running

python PythonAPI/setup.py build_ext install

installed pycocotools to site-packages and resolved the import error.

philferriere

philferriere commented on Nov 2, 2017

@philferriere
Contributor

The package pycocotools requires cython and a C compiler to install correctly. You can also install pycocotools as follows:

  • On Linux, run pip install git+https://github.com/waleedka/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI

  • On Windows, run pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

pirahagvp

pirahagvp commented on Nov 3, 2017

@pirahagvp

git clone https://github.com/pdollar/coco.git

cd coco/PythonAPI
make
sudo make install
sudo python setup.py install

before doing above steps install cython

waleedka

waleedka commented on Nov 3, 2017

@waleedka
Collaborator

Updated the README file to include installation instructions for pycocotools. Thanks @philferriere

YueXiNPU

YueXiNPU commented on Dec 16, 2017

@YueXiNPU

thanks!

YerongLi

YerongLi commented on Feb 12, 2018

@YerongLi

On sudo make install I've got error:

python setup.py build_ext install
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    from Cython.Build import cythonize
ImportError: No module named Cython.Build
Makefile:7: recipe for target 'install' failed
make: *** [install] Error 

I am using python 3.6 and I have both cython and h5py, any ideas why this is happening??

$ conda list cython & conda list h5py
[1] 18446
# packages in environment at /home/yerong/local/Anaconda3:
#
# Name                    Version                   Build  Channel
h5py                      2.7.1            py36h3585f63_0  
# packages in environment at /home/yerong/local/Anaconda3:
#
# Name                    Version                   Build  Channel
cython                    0.27.3           py36h1860423_0  
YerongLi

YerongLi commented on Feb 12, 2018

@YerongLi

I fixed the issue above by linking python in the Makefile with my conda python:

# Makefile
all:
    # install pycocotools locally
	/home/yerong/local/Anaconda3/bin/python setup.py build_ext --inplace
	rm -rf build

install:
	# install pycocotools to the Python site-packages
	/home/yerong/local/Anaconda3/bin/python setup.py build_ext install
	rm -rf build

utahman

utahman commented on Feb 22, 2018

@utahman

I fixed this way:

pip install -U scikit-image
pip install -U cython
pip install git+https://github.com/philferriere/cocoapi.git#egg=pycocotools^&subdirectory=PythonAPI

Chillee

Chillee commented on Mar 9, 2018

@Chillee

@utahman Same, but with the command
pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

raymond30031

raymond30031 commented on Apr 18, 2018

@raymond30031

Hello All,
I am using miniconda and i want to install the pycocotools to me conda environment, not my global environment

When i try to run conda_env/bin/pip install git+https://github.com/waleedka/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI
It prompts me for username and I don't think it is asking for my username.

Does anyone know how to get around this issue?

I am avoiding make install because I am not familiar with make and I don't want to accidentally install things outside of my conda environment.
However, I am opened to suggestions if anyone can tell me how to install to conda environment using make.

--- Update ---
I tried the suggestion from @YerongLi and modified my make file to:
all:
# install pycocotools locally
/home/jkuo/miniconda3/envs/test/bin/python setup.py build_ext --inplace
rm -rf build

install:
# install pycocotools to the Python site-packages
/home/jkuo/miniconda3/envs/test/bin/python setup.py build_ext install
rm -rf build

and then i run the following commands:
make install
python setup.py install

Then I see pycocotools in my site-package:
image

However, I still get the ModuleNotFoundError: No module named 'pycocotools'
image

---Fixed---
Follow the solution of this post

run 'conda install notebook' in the env and jupyter notebook again

Thanks,
JC

kmario23

kmario23 commented on Jun 6, 2018

@kmario23

The solution suggested by @g-mel works like a charm in UbuntuGnome 16.04, Python 3.6 and it directly installs it to site-packages. Thus, no import errors are faced.

waleedka

waleedka commented on Jun 6, 2018

@waleedka
Collaborator

The easiest way I found and it has worked for me on Mac, Ubuntu and Windows:

pip3 install git+https://github.com/waleedka/coco.git#subdirectory=PythonAPI

The full installation steps that I use with conda on Python 3.6 (tested this on Ubuntu 18.04 only):

conda install cudatoolkit cudnn tensorflow-gpu keras cython opencv
pip install imgaug
pip install git+https://github.com/waleedka/coco.git#subdirectory=PythonAPI
sytelus

sytelus commented on Jul 7, 2018

@sytelus

Thanks @philferriere. The pip install hosted on github repo worked well!

47 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @waleedka@sytelus@yustiks@osvadimos@yerzhik

        Issue actions

          ImportError: No module named 'pycocotools' · Issue #6 · matterport/Mask_RCNN