解决conda与ros共存问题/安装conda后catkin编译ros消息和包不通过的解决办法

本文介绍了在Ubuntu下conda与ROS共存时遇到的catkin编译问题。安装conda后,由于catkin依赖的python环境被conda改变,导致编译失败。解决方法包括不初始化conda环境,或者通过命令临时退出conda环境,以确保catkin使用系统默认的python环境进行编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文讨论Ubuntu下的conda与ros共存问题,即安装conda后catkin编译不通过的解决办法。

原因分析

未安装conda前使用catkin编译ros消息和包没有问题,安装了conda后catkin编译不通过。原因在于catkin在编译的时候依赖python,未安装conda之前,catkin的python依赖安装在了系统默认位置,而conda中的python是一个完全隔离的环境,未安装这些依赖,因此编译不通过。

博客中提到了一种解决办法。但即使在conda(python3)环境下安装了博主提到的ros依赖,依然无法使用catkin编译某些ros消息和包,因为他们可能依赖python2。最好的解决办法是让catkin工具查找系统默认的python环境

conda环境

无论是Miniconda还是Anaconda,在安装脚本结束的时候会询问是否进行初始化(conda init)。如果进行初始化,则会在bashrc中添加以下内容:

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/username/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/username/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/username
dwh@PC:~/carla-ros-bridge/catkin_ws$ catkin_make clean Base path: /home/dwh/carla-ros-bridge/catkin_ws Source space: /home/dwh/carla-ros-bridge/catkin_ws/src Build space: /home/dwh/carla-ros-bridge/catkin_ws/build Devel space: /home/dwh/carla-ros-bridge/catkin_ws/devel Install space: /home/dwh/carla-ros-bridge/catkin_ws/install #### #### Running command: "cmake /home/dwh/carla-ros-bridge/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/dwh/carla-ros-bridge/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/dwh/carla-ros-bridge/catkin_ws/install -G Unix Makefiles" in "/home/dwh/carla-ros-bridge/catkin_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/dwh/carla-ros-bridge/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Using PYTHON_EXECUTABLE: /home/dwh/ProgramFiles/anaconda3/envs/carla/bin/python3 -- Using Debian Python package layout -- Could NOT find PY_em (missing: PY_EM) CMake Error at /opt/ros/noetic/share/catkin/cmake/empy.cmake:30 (message): Unable to find either executable 'empy' or Python module 'em'... try installing the package 'python3-empy' Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/all.cmake:164 (include) /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include) CMakeLists.txt:58 (find_package) -- Configuring incomplete, errors occurred! See also "/home/dwh/carla-ros-bridge/catkin_ws/build/CMakeFiles/CMakeOutput.log". Invoking "cmake" failed dwh@PC:~/carla-ros-bridge/catkin_ws$ catkin_make Base path: /home/dwh/carla-ros-bridge/catkin_ws Source space: /home/dwh/carla-ros-bridge/catkin_ws/src Build space: /home/dwh/carla-ros-bridge/catkin_ws/build Devel space: /home/dwh/carla-ros-bridge/catkin_ws/devel Install space: /home/dwh/carla-ros-bridge/catkin_ws/install #### #### Running command: "cmake /home/dwh/carla-ros-bridge/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/dwh/carla-ros-bridge/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/dwh/carla-ros-bridge/catkin_ws/install -G Unix Makefiles" in "/home/dwh/carla-ros-bridge/catkin_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/dwh/carla-ros-bridge/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Using PYTHON_EXECUTABLE: /home/dwh/ProgramFiles/anaconda3/envs/carla/bin/python3 -- Using Debian Python package layout -- Could NOT find PY_em (missing: PY_EM) CMake Error at /opt/ros/noetic/share/catkin/cmake/empy.cmake:30 (message): Unable to find either executable 'empy' or Python module 'em'... try installing the package 'python3-empy' Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/all.cmake:164 (include) /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include) CMakeLists.txt:58 (find_package) -- Configuring incomplete, errors occurred! See also "/home/dwh/carla-ros-bridge/catkin_ws/build/CMakeFiles/CMakeOutput.log". Invoking "cmake" failed
03-16
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值