最开始安装ROS的时候很顺利就创建、编译工作空间成功了,后来重装了系统,一阵子之后再装ROS的时候开始报错,提示没有安装某某包等(我的报错如下),经排查是环境问题
(base) frankchen@Ambush:~/code/ROS/catkin_ws$ catkin_make base path: /home/frankchen/code/ROS/catkin_ws Source space: /home/frankchen/code/ROS/catkin_ws/src Build space: /home/frankchen/code/ROS/catkin_ws/build Devel space: /home/frankchen/code/ROS/catkin_ws/devel Install space: /home/frankchen/code/ROS/catkin_ws/install Creating symlink "/home/frankchen/code/ROS/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/noetic/share/catkin/cmake/toplevel.cmake" #### #### Running command: "cmake /home/frankchen/code/ROS/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/frankchen/code/ROS/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/frankchen/code/ROS/catkin_ws/install -G Unix Makefiles" in "/home/frankchen/code/ROS/catkin_ws/build" #### -- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/frankchen/code/ROS/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /home/frankchen/anaconda3/bin/python3 (found suitable version "3.8.5", minimum required is "3") -- Using PYTHON_EXECUTABLE: /home/frankchen/anaconda3/bin/python3 -- Using Debian Python package layout -- Found PY_em: /home/frankchen/anaconda3/lib/python3.8/site-packages/em -- Using empy: /home/frankchen/anaconda3/lib/python3.8/site-packages/em -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/frankchen/code/ROS/catkin_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /home/frankchen/anaconda3/bin/python3 (found version "3.8.5") -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 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/noetic/share/catkin/cmake/safe_execute_process.cmake:11 (message): execute_process(/home/frankchen/anaconda3/bin/python3 "/opt/ros/noetic/share/catkin/cmake/parse_package_xml.py" "/opt/ros/noetic/share/catkin/cmake/../package.xml" "/home/frankchen/code/ROS/catkin_ws/build/catkin/catkin_generated/version/package.cmake") returned error code 1 Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package_xml.cmake:74 (safe_execute_process) /opt/ros/noetic/share/catkin/cmake/all.cmake:168 (_catkin_package_xml) /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include) CMakeLists.txt:58 (find_package) -- Configuring incomplete, errors occurred! See also "/home/frankchen/code/ROS/catkin_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/frankchen/code/ROS/catkin_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed
可以看到在编译过程中使用了conda的python环境以及conda环境中的各种包,就导致会缺少一些与ROS编译过程中所需的包。所以我们需要使用系统环境,值得注意的是此处我是直接打开终端的,并没有激活某个我所创建的conda环境,实则不然,请注意
当使用过conda,并且将之添加到.bashrc中后,每次打开终端都已经进入conda名为"(base)"的环境了,如上图最左侧所示,所以我们需要退出这个环境。一些博客给出的解决方法是到.bashrc文件中将有关conda路径的代码注释掉,但之后要用到conda的时候还要取消注释,很繁琐,直接在终端中用命令
$ conda deactivate
退出环境就可以了,如图
然后重新创建编译工作空间就可以了。



