ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

import cv2 error caused by ROS!

asked 2018-05-08 12:36:37 -0500

nrb gravatar image

updated 2018-05-08 12:45:03 -0500

I have anaconda installed. which python gives me the following output:


Now when I start python on command line, it starts the anaconda's python but import cv2 gives me the following error:

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

In the .bashrc I have :

export PATH="/home/nehal/anaconda3/bin:$PATH"
export PYTHONPATH="/home/nehal/anaconda3/lib/python3.6/dist-package‌​s:$PYTHONPATH"
source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash

and nothing else related to python in .bashrc

nehal@nehal-Inspiron-5559:~$ echo $PYTHONPATH
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2018-05-08 13:21:15 -0500

ahendrix gravatar image

You're mixing Anaconda (which is apparently Python 3) with python modules that are compiled for cPython 2.7. These are incompatible and won't work together.

You may want to try either:

  • Don't use Anaconda when you use ROS (use one or the other, but not both)
  • Recompile ROS and the OpenCV python library to use Anaconda (I have no idea how to do this, but you can probably find instructions online)
edit flag offensive delete link more


Thank you!

nrb gravatar image nrb  ( 2018-05-08 13:30:11 -0500 )edit

answered 2019-08-27 12:31:06 -0500

lochlomond gravatar image

updated 2019-08-27 16:33:19 -0500

ahendrix gravatar image

i met the same problem, here is how i "solved" it, ugly but worked

write "import cv2" into

import sys
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages') # in order to import cv2 under python3
import cv2
sys.path.append('/opt/ros/kinetic/lib/python2.7/dist-packages') # append back in order to import rospy
edit flag offensive delete link more


Wow! It's working. Thanks a lot!

amiryanj gravatar image amiryanj  ( 2019-12-24 08:38:17 -0500 )edit

Thanks a lot, it works

pry gravatar image pry  ( 2020-03-21 05:14:55 -0500 )edit

solved ,thanks

myth1665 gravatar image myth1665  ( 2020-05-11 21:35:27 -0500 )edit

this should be an accepted answer though

Farid gravatar image Farid  ( 2020-07-31 06:46:23 -0500 )edit

answered 2019-12-26 06:35:44 -0500

mirchi gravatar image

updated 2019-12-27 16:45:24 -0500

jayess gravatar image

bashrc file

source /opt/ros/kinetic/setup.bash 
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311
edit flag offensive delete link more

Question Tools



Asked: 2018-05-08 12:36:37 -0500

Seen: 8,825 times

Last updated: Dec 27 '19