ros安装 catkin_make失败 ImportError: “from catkin_pkg.package import parse_package“ failed: No module na

ros安装 catkin_make失败 ImportError: “from catkin_pkg.package import parse_package” failed: No module named ‘catkin_pkg’

在ros安装时,运行到建立工作空间,然后编译catkin_make出错。

情况一:如果是你错误使用了Python3版本,那么就将编译命令由catkin_make改为

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2

参考链接1
情况二:catkin_pkg的位置可能不在你的PYTHONPATH上,参考
参考链接2

我面临的是情况一,debug过程如下所示:

cxl@cxl-laptop:~/catkin_ws$ catkin_make
Base path: /home/cxl/catkin_ws
Source space: /home/cxl/catkin_ws/src
Build space: /home/cxl/catkin_ws/build
Devel space: /home/cxl/catkin_ws/devel
Install space: /home/cxl/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/cxl/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/cxl/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.6.9", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/cxl/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python3 (found version "3.6.9") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
  execute_process(/usr/bin/python3
  "/opt/ros/melodic/share/catkin/cmake/parse_package_xml.py"
  "/opt/ros/melodic/share/catkin/cmake/../package.xml"
  "/home/cxl/catkin_ws/build/catkin/catkin_generated/version/package.cmake")
  returned error code 1
Call Stack (most recent call first):
  /opt/ros/melodic/share/catkin/cmake/catkin_package_xml.cmake:74 (safe_execute_process)
  /opt/ros/melodic/share/catkin/cmake/all.cmake:168 (_catkin_package_xml)
  /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:20 (include)
  CMakeLists.txt:58 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/cxl/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/cxl/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

注意到

--Using PYTHON_EXECUTABLE: /usr/bin/python3
......
-- Found PythonInterp: /usr/bin/python3 (found version "3.6.9") 
-- Using Python nosetests: /usr/bin/nosetests-2.7

发现了Python3,据说ros和Python3兼容性不好,于是我将编译命令从catkin_make改为

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2

再次编译成功了

cxl@cxl-laptop:~/catkin_ws$ catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2
Base path: /home/cxl/catkin_ws
Source space: /home/cxl/catkin_ws/src
Build space: /home/cxl/catkin_ws/build
Devel space: /home/cxl/catkin_ws/devel
Install space: /home/cxl/catkin_ws/install
####
#### Running command: "cmake /home/cxl/catkin_ws/src -DPYTHON_EXECUTABLE=/usr/bin/python2 -DCATKIN_DEVEL_PREFIX=/home/cxl/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/cxl/catkin_ws/install -G Unix Makefiles" in "/home/cxl/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/cxl/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/melodic
-- This workspace overlays: /opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/cxl/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.28
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cxl/catkin_ws/build
####
#### Running command: "make -j12 -l12" in "/home/cxl/catkin_ws/build"
####

记录一下。
我可能是在Ubuntu安装的时候错误的使用了

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

造成的。
在这里插入图片描述

  • 19
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值