using cv_bridge with python 3.6 on ubunut 16.04

asked 2020-07-14 13:57:26 -0600

waspinator gravatar image

updated 2020-07-14 14:55:57 -0600

I need to use python 3.6 in a kinetic ROS package that manipulates images using opencv. To transfer images in and out of the package I'm using cv_bridge, but it is only supported on python 2.7 so I'm trying to figure out a way to get around that. I have seen reports of this being possible but I'm unable to reproduce the results.

Below is the dockerfile which I use to build my environment. Running it, starting a python3.6 shell and importing cv_bridge

from cv_bridge.boost.cv_bridge_boost import getCvType

gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

running source /cv_bridge_ws/install/setup.bash doesn't help. Strangely though if I run source /cv_bridge_ws/install/setup.bash another time then it seems to work.

How do I properly source the workspace to use cv_bridge?

FROM ros:kinetic

RUN apt-get update && apt-get install -y \
    software-properties-common python-catkin-tools \
    curl wget python-dev build-essential checkinstall \
    libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

RUN apt-get update && apt-get install -y \
    ros-kinetic-cv-bridge \
    ros-kinetic-image-transport \
    ros-kinetic-tf \
    ros-kinetic-diagnostic-updater \

RUN add-apt-repository -y ppa:deadsnakes/ppa \
    && apt-get update && apt-get install -y python3.6-dev

RUN curl -o && \
    python2 && python3.6

RUN pip3 install opencv-python PyYAML cython rospkg

RUN ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/
RUN mkdir --parents /cv_bridge_ws/src
WORKDIR /cv_bridge_ws
RUN catkin config \
    -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
RUN catkin config --install
RUN git -C /cv_bridge_ws/src clone -b 1.12.8 
RUN catkin config --extend /opt/ros/kinetic && \
    catkin clean --yes && \
    catkin build
edit retag flag offensive close merge delete


Maybe you should change ROS_PYTHON_VERSION environment variable?

Solrac3589 gravatar image Solrac3589  ( 2020-07-17 05:42:09 -0600 )edit