I have first installed openCV from source using this script. When I tested it was working well.
After I installed ROS kinetic, and open python3
and run import cv2
, got the following error:
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
I tried to remove
/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so.
Now It is working.Actually, I also encounter this problem. I just commented-out the source:
and then, open the terminal, In the anaconda lib path I executed:
/home/apg/miniconda3
is the path where my python3 was installed, and/opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so
was the path thatopencv-python
was installed.I don't know yet why this command works, but it did work for me to solve the problem that I was not able to import cv2 previously.
During ROS setup running
/opt/ros/kinetic/setup.bash
, the script between other things will go to every distribution package for python2 and python3 and it will add it to the python system path. When you try to importcv2
using python3 it will first find the cv2 binding for Python2 as included in the path.If you are not planning on using python2.7 at all for your ROS project, consider removing entirely the python2.7 OpenCV package, so it won't be added to the path when running the ros setup script:
$ rm /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so
Another more gentle approach if you are planning to use both Python versions would be to create two virtual environments with the correct bindings, and activate one or another depending on your requirements.