[Problem Solved] Installing PyKDL in the Linux-conda environment cannot link the .so dynamic library

Project scenario:

Recently, I need to deploy the PyKDL library. I encountered a strange problem and have been troubled for several days. The problem description and my solution process are listed below.

The github warehouse address of the orocos-kdl library:
https://github.com/orocos/orocos_kinematics_dynamics


Problem Description

I have installed and tested the kdl-py library according to install.md on another computer before, but there is a problem when deploying it on a new computer today:

ModuleNotFoundError: No module named 'PyKDL'

Cause Analysis:

At first, I thought it was a dynamic library that could not be linked in the conda environment /usr/local/lib, so I directly threw the dynamic library into the site-packages directory of the python environment in conda, and the following error occurred:

undefined symbol: PyFrame_GetBack

For the problem of undefined symbols, trace the source through the following methods:

nm -gDC PyKDL.so | grep Py

It can be seen that most of the symbols in python are not defined, so it is not that conda cannot link the dynamic library, but that there is a problem when using pybind11 to compile the C++ library .

In cmake, there is no error message of pybind11, indicating that there is no problem with its installation, so it is still an environmental problem, so directly look at the cmakelist in pykdl, and notice the following parts:

if(DEFINED ENV{ROS_PYTHON_VERSION})
  SET(PYTHON_VERSION $ENV{ROS_PYTHON_VERSION} CACHE STRING "Python Version")
else()
  SET(PYTHON_VERSION 3 CACHE STRING "Python Version")
endif()

I found that its cmake uses the Python version of ROS, and my computer only has python in the conda environment.


solution:

So when cmake, we need to specify the path of python and its library files:

cmake -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so  \
           -DPYTHON_INCLUDE_DIR=/usr/include/python3.8 \
           -DPYTHON_EXECUTABLE=/usr/bin/python3.8     ..

or

cmake -DPYTHON_LIBRARY=/home/zhou/anaconda3/lib/libpython3.9.so   \
          -DPYTHON_INCLUDE_DIR=/home/zhou/anaconda3/include/python3.9 \
                     -DPYTHON_EXECUTABLE=/home/zhou/anaconda3/bin/python3.9     ..

Then, throw the compiled dynamic library into the site-packages in envs, and import it directly to use it.

Guess you like

Origin blog.csdn.net/qq_43557907/article/details/127818837