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

Using C++ class in Python 2.7 and 3.x

asked 2017-07-28 08:41:23 -0500

Thomas_Blo gravatar image

Hey, I was trying to write a Python C++ wrapper as described in the Tutorial: "Using a C++ class in Python".

Now to my question, is there a way to compile the Module for Python 2.7 and 3 simultaneously using catkin? So i can import the wrapper Class in both versions?

Because currently when Importing the wrapper to python 3 this error is thrown: ImportError: dynamic module does not define module export function (PyInit__wrapper_cpp) Since i can only link it against the python 2 libs.

Under Python 2 it is currently working without any errors.

Thanks for your help, Thomas

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-07-30 17:26:34 -0500

allenh1 gravatar image

It's doable, but pretty disgusting (macros/pragmas are very involved, due to major difference in the wrapper API). I wouldn't bother with the python 2/3 backwards compatibility, just stick with 3 if you wrote it in 3. Mixing python versions in ROS gets messy very quickly.

edit flag offensive delete link more

Question Tools



Asked: 2017-07-28 08:41:23 -0500

Seen: 242 times

Last updated: Jul 28 '17