ImportError: No module named cv2 while running tools/demo.py

741 views
Skip to first unread message

Chan Kim

unread,
Jan 20, 2016, 9:23:05 AM1/20/16
to Caffe Users
Hi 
to install caffe and faster-rcnn. (with help from my colleague). I use CentOS6.7 and used anaconda.
I downloaded the pretrained models.
When I press tools/demo.pl,
I get this error :
ckim@stph45:~/Neuro/py-faster-rcnn] tools/demo.py 
Traceback (most recent call last):
  File "tools/demo.py", line 18, in <module>
    from fast_rcnn.test import im_detect
  File "/home/ckim/Neuro/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 15, in <module>
    import cv2
ImportError: No module named cv2

What's wrong with it?
THe only cv2.so file I can find is /usr/local/lib/python2.6/site-packages/cv2.so but I'm afraid it's not the cv2 the demo.py is looking for.
Is it the opencv that comes with the CentOS or a special opencv for python.(I guess the later)
Do I have to install the 'special' opencv for python? or 
Do I have set any enrionment variable like PYTHON_PATH?
Thanks in advance.


Jan C Peters

unread,
Jan 25, 2016, 7:28:35 AM1/25/16
to Caffe Users
Is it the opencv that comes with the CentOS or a special opencv for python.(I guess the later)

Well, you need both, actually. The "OpenCV that comes with CentOS" (I think the rpm package is just called "opencv") needs to be installed because it contains the actual runtime library with its algorithms. Additionally, to use this library from python, you need a python wrapper, which acts as a bridge between python and the underlying C++ library, but does not add any real functionality. This wrapper comes with the package "opencv-python" in CentOS. The cv2.so you found may be the python layer implementation. Nevertheless, if you installed both these packages in a reasonable way (through your package manager [yum] or with pip install), this error should not come up. PYTHONPATH needs to be set only for python modules that do not reside in the standard paths (should not be the case for you). A case where it makes sense is for using pycaffe.

Jan
Reply all
Reply to author
Forward
0 new messages