解决 IsaacSim 5.0 与 ROS2 Python 版本冲突的完整指南
随着 IsaacSim 5.0 升级到了 python3.11,很多开发者在尝试使用 ROS2 时遇到了兼容性问题。默认情况下,ROS2 官方提供的预编译包仅支持 python3.10,在IsaacSim 5.0环境下使用 ROS2 会出现如下错误:
AttributeError: _ARRAY_API not found
为了解决这个问题,可以从两个方向入手:一是回退到 ROS2 支持的 python3.10 环境,并使用isaacsim4.5 ,二是让 ROS2 在python3.11上进行适配, 这里介绍如何在isaacsim5.0中使用ros2
一:使用Python 3.10的ROS2标准环境
1. 检查并设置 UTF-8 本地化环境
locale # 查看当前设置sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8locale # 验证设置是否生效
2. 安装必要依赖和添加源
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
3. 下载并安装 ROS2 官方 APT 源
export ROS_APT_SOURCE_VERSION=$(curl -s https://api.github.com/repos/ros-infrastructure/ros-apt-source/releases/latest | grep -F "tag_name" | awk -F\" '{print $4}')
curl -L -o /tmp/ros2-apt-source.deb "https://github.com/ros-infrastructure/ros-apt-source/releases/download/${ROS_APT_SOURCE_VERSION}/ros2-apt-source_${ROS_APT_SOURCE_VERSION}.$(. /etc/os-release && echo $VERSION_CODENAME)_all.deb"
sudo dpkg -i /tmp/ros2-apt-source.deb
4.更新系统并安装 ROS2
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop
sudo apt install ros-dev-tools5. 启动 ROS2 环境
source /opt/ros/humble/setup.bash
# 可以将上行加入 ~/.bashrc,实现每次终端自动加载
二:在Python 3.11下适配ROS2
在IsaacSim 5.0 的默认 Python 3.11 环境中直接使用 ROS2,可以通过编译 ROS2 工作空间来实现兼容:
git clone https://github.com/isaac-sim/IsaacSim-ros_workspaces.git
cd IsaacSim-ros_workspaces
./build_ros.sh -d humble -v 22.04
source build_ws/humble/humble_ws/install/local_setup.bash
这个方法会在本地构建 ROS2,使其可以在 Python 3.11 下使用,但编译过程可能耗时较长
