I had a computer vision project on Ubuntu 14.04 with ROS indigo and python3, then I had to move on Ubuntu 16.04 with ROS kinetic. Here I ran into multiple issues:
1) I installed opencv, but couldn't import it in python3, the error message was:
Traceback (most recent call last):
File "test.py", line 2, in <module>
import cv2
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so:
undefined symbol: PyCObject_Type
What I figured out is just rename cv2.so
cd /opt/ros/kinetic/lib/python2.7/dist-packages/
sudo mv cv2.so cv2_ros.so
Then I was able to import cv2 and use it
2) Then I couldn't import rospy, but installation of python3-catkin-pkg-modules and python3-rospkg-modules fixed that problem
3) Finally I ran into an issue with cv_bridge it says:
[ERROR] [1520780674.845066]: bad callback: <bound method ViewsBuffer.update of <__main__.ViewsBuffer object at 0x7f5f45a07f28>>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "test.py", line 48, in update
im = self.bridge.imgmsg_to_cv2(im, "bgr8")
File "/opt/ros/kinetic/lib/python2.7/dist-packages/cv_bridge/core.py", line 163, in imgmsg_to_cv2
dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/cv_bridge/core.py", line 99, in encoding_to_dtype_with_channels
return self.cvtype2_to_dtype_with_channels(self.encoding_to_cvtype2(encoding))
File "/opt/ros/kinetic/lib/python2.7/dist-packages/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
I believe the problem is in the cv_bridge_boost.so file. I also tried to build cv_bridge from https://github.com/ros-perception/vision_opencv, but it automatically builds for python2.7, I was trying to modify CMakeLists.txt a little bit to specify python3 there, but I don't have much experience with CMakeLists, so it didn't work. I also tried to copy cv_bridge module to my project folder, but it didn't change much and it still points on that cv_bridge_boost.so file. Another thing to mention is that cv_bridge works fine with python2.7, but my project requires python3.5.