尝试在 ROS 中创建 catkin 工作区时遇到 CMake 错误,因为它找不到 PythonInterp



我在尝试在ROS中创建catkin工作区时遇到CMake错误,因为它找不到PythonInterp。它找到了一个不合适的版本"1.4",但它至少需要有 2。但是,我已经为ros下载了更高版本的python。

这就是我跑步时得到的catkin_make

nasa@nasa-VirtualBox:~/catkin_ws$ catkin_make
Base path: /home/nasa/catkin_ws
Source space: /home/nasa/catkin_ws/src
Build space: /home/nasa/catkin_ws/build
Devel space: /home/nasa/catkin_ws/devel
Install space: /home/nasa/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/nasa/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/nasa/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find PythonInterp: Found unsuitable version "1.4", but required
is at least "2" (found /home/nasa/catkin_ws/build/python3)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:376 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.10/Modules/FindPythonInterp.cmake:152 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
/opt/ros/melodic/share/catkin/cmake/python.cmake:4 (find_package)
/opt/ros/melodic/share/catkin/cmake/all.cmake:163 (include)
/opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:56 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/nasa/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/nasa/catkin_ws/build/CMakeFiles/CMakeError.log".
Makefile:320: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed

使用命令$python -V检查 python 的版本。

如果版本为 2.7,则:

  1. 转到catkin_ws
  2. 删除文件夹开发并重新构建
  3. 在工作区中打开另一个终端,然后重试。

解决方案可能是清理您的工作区。正如这里所暗示的那样,搜索错误后谷歌中的第一个链接,问题是CMakeCache.txt。根据您使用的是catkin build还是catkin_make,您可以在 catkin 工作区中运行catkin cleancatkin_make clean。仅删除工作区中的 devel 和 build 文件夹也应该适用于任一构建系统。

您还可以更快地获得有关 ROS 相关问题的答案 https://answers.ros.org/questions/

如果清理工作区不能解决问题,请检查从终端python --version报告的python版本。此外,如果您安装了新版本的python并从同一终端尝试构建工作区,则相关的ENVIRONMENT路径可能尚未在该shell中更新。运行exec bash或启动新终端并尝试构建工作区。