说明

项目需求需要使用python写一个3D检测的ROS2节点,通过修改ROS2的配置文件来间接的让系统使用虚拟环境中的Python解释器
参考链接ROS2虚拟环境配置指南

步骤

  1. 修改setup.cfg文件,添加如下配置
# src/{node}/setup.cfg
[build_scripts]
executable = /usr/bin/env python3
  1. 创建虚拟环境 在创建虚拟环境时,需要将系统环境中的ROS2包链接到虚拟环境中
python3 -m venv your_venv_name --system-site-packages --symlinks
  1. 激活ros2环境配置和虚拟环境配置
source /opt/ros/foxy/setup.zsh
source ./venv/bin/activate
  1. colcon build并运行
colcon build
source install/setup.bash
ros2 run package_name node_name
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐