Search code examples
importerroropencv3.0ros

Import error ROS python3 opencv


Is there a way where I can import both opencv2 and rospy successfully in python3. Because right now I get an error.

Traceback (most recent call last): File "", line 1, in ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type

removing the line "source /opt/ros/kinetic/setup.bash" from my bash file solves the problem of importing opencv but now I cant import rospy


Solution

  • This happens since ROS creates its own open cv ,which is compatible with python2 only.To solve this

    1. You need to rename the Cv of Ros located at /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so to something else, example cv_renamed.so and then you should be able to import it
    2. Since Ros cannot coexist for python2 and python3 , It is recommended to have a virtual environment(conda,virtual env)