Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import pycocotools from script #8

Closed
mprat opened this issue Oct 17, 2015 · 12 comments
Closed

Unable to import pycocotools from script #8

mprat opened this issue Oct 17, 2015 · 12 comments

Comments

@mprat
Copy link

mprat commented Oct 17, 2015

I am playing with the pycocotools package and found that I was not able to import pycocotools from a python script, but COULD import it from ipython. For example:

python -c "import pycocotools"

yields

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pycocotools

But, doing

ipython
In [1]: import pycocotools

Works fine.

Has anyone seen this problem before? I'm working in a virtual environment.

@mprat
Copy link
Author

mprat commented Oct 18, 2015

Uh, nevermind. This was a problem with where the library was installed and which version of Python was being used by iPython.

@mprat mprat closed this as completed Oct 18, 2015
@PrateekRaisinghani
Copy link

So, where should we install the library and which version of Python worked for you?

@mprat
Copy link
Author

mprat commented Sep 18, 2016

I specifically used Python 2.7 installed on my mac using homebrew. The problem was happening because I had installed the package into a virtualenv, but was not using the virtualenv for launching iPython, where I was trying to do the import.

@hphong591992
Copy link

hphong591992 commented Sep 30, 2016

Can you clarify a little bit more how you fix this error?

Thank you.

Nevermind, I fixed it as going to /PythonAPI/ and call python setup.py install again.

@mprat
Copy link
Author

mprat commented Sep 30, 2016

The solution differs greatly based on your operating system, use/not-use of virtual environments, how you launched Python, etc. If you elaborate on how you use Python on your system then the solution will become clearer.

The basic idea is that you have to install the package in the same version / instance of Python that you are trying to import the package from.

@monajalal
Copy link

I have the followings for solving the problem:

import sys
sys.path.append('/home/mona/mscoco/coco/PythonAPI')
p(sys.path)
from pycocotools.coco import COCO

And I also have:

git clone https://github.com/pdollar/coco.git
and then you should do a make in the PythonAPI repo.

@Thrianadh
Copy link

Thanks monajalal
I re-solved the problem
thanks for Posting

@Jinnaouc
Copy link

@monajalal
Thanks monajalal
I also solved my problem with your solution, but a delete the p(sys.path). But I don't know too much about python, when I use your method, there is an error: p is not defined. So I delete that line, it still works well.

@salihkaragoz
Copy link

This also another solution for virtual environments.
git clone https://github.com/cocodataset/cocoapi.git
open venv
source venv/bin/activate
cd cocoapi/PythonAPI
python setup.py install
Don't use --user because if you use this parameter pycocotools packet will installed to your local dist-packages not in venv.

@cclauss
Copy link
Contributor

cclauss commented May 3, 2018

@salihkaragoz That workaround does not work anymore.

@vyviansomaya
Copy link

It still fails for me. these are the following steps I took

$ git clone https://github.com/pdollar/coco.git
$ cd coco/PythonAPI
$ make
$python setup.py install

I open a new notebook in AWS SageMaker in the PythonAPI directory and tried to import pycocotools, it succeeded.
Next, I tried "from pycocotools.coco import COCO" and got the "No module named _mask" output. I have done everything in the comments above and I still fail. The only difference I notice is that I'm using SageMaker . should that be the issue? or if its something else please let me know!

@khan958
Copy link

khan958 commented Oct 17, 2019

Same Problem with me. How can i solve it .
File "C:\Users\Jayden\Anaconda3\lib\site-packages\pycocotools\mask.py", line 3, in
import pycocotools._mask as _mask

ModuleNotFoundError: No module named 'pycocotools._mask

mfrashad pushed a commit to mfrashad/cocostuffapi that referenced this issue Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants