Search code examples
pythonversionros

How to solve the error occurred when I try to use function in tf_conversions in ROS1-melodic in a python3 environment


I am learning ROS-melodic, but my python environment is created by anaconda and is 3.9. So when I try to use functions in tf_conversions, an error saying ImportError: dynamic module does not define module export function (PyInit_PyKDL) occurred

I searched the Internet and they all say that I should rebuild the pybind11 and PyKDL library. So I cloned the orocos_kinematics_dynamics repository down and built successfully with the orocos_kinematics_dynamics/orocos_kdl c++ lib, but whenever I tried to build python lib with the orocos_kinematics_dynamics/python_orocos_kdl, when doing make step, the error would occur:

In file included from /usr/local/include/pybind11/attr.h:13:0,
                 from /usr/local/include/pybind11/detail/class.h:12,
                 from /usr/local/include/pybind11/pybind11.h:13,
                 from /home/dongxuan/catkin_ws_test/src/python_orocos_kdl/PyKDL/PyKDL.h:26,
                 from /home/dongxuan/catkin_ws_test/src/python_orocos_kdl/PyKDL/PyKDL.cpp:27:
/usr/local/include/pybind11/detail/common.h:269:6: error: #error "PYTHON < 3.6 IS UNSUPPORTED. pybind11 v2.9 was the last to support Python 2 and 3.5."
 #    error "PYTHON < 3.6 IS UNSUPPORTED. pybind11 v2.9 was the last to support Python 2 and 3.5."

And lots of more errors in subsequence. But if I type python --version, it will show 3.9.12. so I don't know where the setting is unsuitable.


Solution

  • ROS Melodic is built natively for Python2.7, not >=3. There are workarounds to try and get Python3 working with Melodic, but none of them should be considered stable.

    For ROS1 Noetic is the only distro that natively supports Python3. If you need to use modules with Python3 you should only be using Noetic.