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
ROS provides a very simple integration with OpenCV, the most widely used open source Computer Vision library. However, it does not ship a specific Debian for ROS kinetic because that would force users to use a single version.
It looks like this problem is caused by ROS adding /opt/ros/kinetic/lib/python2.7/dist-packages to the python path. This actually happens when you activate ROS with the command source /opt/ros/kinetic/setup.bash. This line is often added at the end of your bashrc file, in /home/username/.bashrc.
A workaround is to remove this line from the bashrc file. This way the python3 opencv packages will be correctly used, and you can still run source /opt/ros/kinetic/setup.bash to use ROS. However, this does mean you cannot use ROS and python3 from the same environment.
Hopefully someone can come up with a better answer, but this should work until then.
If you are working with anaconda, activate the environment you want to work from, and remove the culprit from sys.path.
To do so, open a python3 console, from which:
>>> import sys >>> print(sys.path) You will see several path, among which you should notice:
'/opt/ros/kinetic/lib/python2.7/dist-packages' Then remove it:
>>> sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages') Tested with python3.5 on anaconda3 with locally compiled opencv. This is likely applicable to virtualenvs as well.
For a permanent solution, remove the path '/opt/ros/kinetic/lib/python2.7/dist-packages' from ~/.bashrc as mentioned in @Paul's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With