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

import cv2 error caused by ROS!

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

nrb gravatar image

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

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

/home/nehal/anaconda3/bin/python


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/cv2.so: 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"
ROS_IP=
ROS_HOSTNAME=
ROS_MASTER_URI=
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
/home/nehal/catkin_ws/devel/lib/python2.7/dist-packages:/opt/ros/kinetic/lib/python2.7/dist-packages:/home/nehal/anaconda3/lib/python3.6/site-package‌​s:/home/nehal/anaconda3/lib/python3.6/dist-package‌​s:/home/nehal/anaconda3/lib/python3.6/dist-package‌​s:/home/nehal/anaconda3/lib/python3.6/dist-package‌​s:/home/nehal/anaconda3/lib/python3.5/dist-package‌​s:/home/userx/anaconda3/lib/python3.5/dist-package‌​s:/home/userx/anaconda3/lib/python3.5/dist-package‌​s:/home/userx/anaconda3/lib/python3.5/dist-package‌​s
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
3

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

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

Comments

Thank you!

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

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

lochlomond gravatar image

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

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

Comments

Wow! It's working. Thanks a lot!

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

Thanks a lot, it works

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

solved ,thanks

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

this should be an accepted answer though

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

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

mirchi gravatar image

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

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

2 followers

Stats

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

Seen: 8,907 times

Last updated: Dec 27 '19