Ask Your Question
0

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:

/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

2 Answers

Sort by » oldest newest most voted
3

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

Comments

Thank you!

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

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

Seen: 1,928 times

Last updated: Aug 27