0
$\begingroup$

Rosanswers logo

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?


Originally posted by tirafesi on ROS Answers with karma: 5 on 2020-11-29

Post score: 0

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

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//setup.bash) or your workspace (install/setup.bash) before running VS code. It should recognize all the ROS components then,


Originally posted by Mario Garzon with karma: 802 on 2020-11-30

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by RFRIEDM_Trimble on 2021-04-22:
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/**"

Comment by Mario Garzon on 2021-04-26:
If you are using Docker containers with VS Code, I'll definitely recommend you to check this: vscode-docker-ros2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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"]

Originally posted by wouterheerwegh with karma: 11 on 2021-09-10

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.