Using a different version of OpenCV in Ros (kinetic)

I have fixed it by forcing ros to use python3 by using #/usr/bin/env python3 instead of just python (python2.7). Then it gave an error that in the python3 environment that it didn’t know OpenCV yet.
I ran: $pip3 install --user opencv-python for a python3 opencv library.

After that it still gave an error:

>>> import cv2
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

After days of troubleshooting I came across a workaround that basicly softlinks the cv2.so in kinetic/lib/python2.7/dist-packages/ with a different cv2.so. One of the version 3.4.4 in my case

I ran: $sudo ln -sf /home/yournamehere/anaconda3/lib/python3.7/site-packages/cv2.so /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so

From what I understand this let’s the OS point the import of python to another package. Even outside of ROS. I don’t really understand everything about this yet, but it did make it possible to use OpenCV’s dnn module and YOLOv3 inside a ROS node!

The only thing I can imagine not working now is when you try to import cv2 in python 2.7. If that turns out to be it there’s no downside for me. I prefer python3 anyway.

Does anyone know what I might run into when I softlink files? So far everything still seems to be working!

Kind regards,

Mitchel Mulder