编译Python3版本geometry2时出现CMake错误的解决方法求助
This error pops up because CMake can’t locate the Python 3.6 shared library at the path it’s expecting. Let’s walk through practical fixes step by step:
Step 1: Find where your system stores libpython3.6.so
First, run this command to locate the actual library file on your machine:
find /usr/lib -name "libpython3.6.so"
You’ll likely get a path like /usr/lib/x86_64-linux-gnu/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so (the exact path depends on your distro and architecture).
Step 2: Fix the path mismatch
You have two reliable options here:
Option A: Create a symbolic link
Link the actual library to the path CMake is looking for:
sudo ln -s /path/to/your/libpython3.6.so /usr/lib/python3.6/config/libpython3.6.so
Replace /path/to/your/libpython3.6.so with the path you found in Step 1.
Option B: Specify the library path directly in catkin_make
Instead of modifying system paths, pass the correct library path to CMake during the build:
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
Note: Some systems use libpython3.6m.so (with the m suffix for pymalloc support) instead of libpython3.6.so — adjust the path to match what your find command returned.
Step 3: Ensure Python 3.6 dev files are installed
If the library file doesn’t exist at all, you’re probably missing the Python development package. Install it with:
sudo apt-get install python3.6-dev
After trying one of these fixes, clean your build directory and rebuild to apply changes:
cd ~/geometry2_ws catkin clean catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
Why this happens
On modern 64-bit systems, Python’s development libraries are often stored in architecture-specific subdirectories (like x86_64-linux-gnu) instead of the older /usr/lib/python3.6/config path. The tf2_py CMake configuration might be hardcoded to this outdated path, leading to the missing target error.
内容的提问来源于stack exchange,提问作者sudo-Boris

