Shiva Reddy
Shiva Reddy

Reputation: 37

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

Upvotes: 0

Views: 2247

Answers (1)

zishan ahmed
zishan ahmed

Reputation: 101

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)

Upvotes: 0

Related Questions