Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install COCO PythonAPI in python3

Tags:

python

mscoco

It seems the COCO PythonAPI only support python2. But peoples do use it in python3 environment.

I tried possible methods to install it, like

python3 setup.py build_ext --inplace
python3 setup.py install

But python3 setup.py install will fail due to coco.py and cocoeval.py containning python2 print function.

Update: solved by updating the COCO PythonAPI project. Leave this question for people facing the same issue.

like image 458
Panfeng Li Avatar asked Mar 15 '18 23:03

Panfeng Li


People also ask

What is Pycocotools Coco?

pycocotools is a Python API that. # assists in loading, parsing and visualizing the annotations in COCO.

Why am I getting a Modulenotfounderror No module named Pycocotools _mask error in my code?

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.


2 Answers

Try the following steps:

  1. Use git clone to clone the folder into your drive. In this case, it should be git clone https://github.com/cocodataset/cocoapi.git
  2. Use terminal to enter the directory, or open a terminal inside the directory
  3. Type in 2to3 . -w. Note that you might have to install a package to get 2to3. It is an elegant tool to convert code from Python2 to Python3; this code converts all .py files from Python2-compatible to Python3-compatible
  4. Use terminal to navigate to the setup folder
  5. Type in python3 setup.py install

This should help you install COCO or any package intended for Python2, and run the package using Python3. Cheers!

like image 153
troymyname00 Avatar answered Oct 20 '22 16:10

troymyname00


I have completed it with a simple step

pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

** before that you need to install Visual C++ 2015 build tools on your path

enter image description here

like image 30
Lanka Avatar answered Oct 20 '22 17:10

Lanka