ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can I make VS Code recognize ros2 python packages?

asked 2020-11-29 11:51:09 -0500

tirafesi gravatar image

When working with python launch files, VS Code always complaints about unresolved imports, such as unresolved import 'launch' and unresolved import 'launch_ros.actions'. Of course, this also means I don't have access to IntelliSense.

How can I make VS Code recognize ros2 python packages?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2020-11-30 04:47:37 -0500

HI,

The easiest way to work with VS Code is to use the Visual Studio Code Extension for ROS

If you have it installed, just make sure you source the ROS setup (i.e. /opt/ros/<rosdistro>/setup.bash) or your workspace (install/setup.bash) before running VS code. It should recognize all the ROS components then,

edit flag offensive delete link more

Comments

1

If ROS2 is running in a Docker container, with VSCode using the remote containers extension, I cannot find a way to source ROS before VSCode opens. As a fix, I have installed the ROS extension.

  • In .vscode/settings.json, add the following:

    • "ros.distro": "foxy"
  • In .vscode/c_cpp_properties.json, add this to the includePath list:

    • "/opt/ros/foxy/include/**"
RFRIEDM_Trimble gravatar image RFRIEDM_Trimble  ( 2021-04-22 12:33:06 -0500 )edit

If you are using Docker containers with VS Code, I'll definitely recommend you to check this: vscode-docker-ros2

Mario Garzon gravatar image Mario Garzon  ( 2021-04-26 09:10:28 -0500 )edit
1

answered 2021-09-10 02:37:34 -0500

wouterheerwegh gravatar image

You could also add the path to your python folder in the settings.json file as follows:

"python.autoComplete.extraPaths": ["/opt/ros/foxy/lib/python3.8/site-packages"]
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-11-29 11:50:13 -0500

Seen: 5,217 times

Last updated: Nov 30 '20