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

ROS2 import Python modules

asked 2020-12-08 17:02:14 -0500

infantasy gravatar image

updated 2020-12-08 19:23:22 -0500

If I need to import let's say numpy in a ROS2 Python node, how does that work? I added it to package.xml but I'm getting getting "ModuleNotFoundError: No module named 'dynamixel_sdk'". Do I need to add it somewhere use? Should I use a venv?

edit retag flag offensive close merge delete

Comments

Btw, this question was asked here as well but didn't receive an answer: https://answers.ros.org/question/3656...

infantasy gravatar image infantasy  ( 2020-12-08 17:04:51 -0500 )edit

Just following up... It doesn't seem like it did anything to add it to package.xml, although I saw this in some Github repos. I think I will just use a venv / requirements.txt, although I'm not sure that this is the best approach.

infantasy gravatar image infantasy  ( 2020-12-09 00:58:02 -0500 )edit

We spent a little time documenting this a bit more, maybe this will help: https://index.ros.org/doc/ros2/Tutori...

mjcarroll gravatar image mjcarroll  ( 2020-12-22 12:31:19 -0500 )edit

Thanks so much for the documentation!! I'm guessing you meant to link to https://index.ros.org/doc/ros2/Tutori...

infantasy gravatar image infantasy  ( 2020-12-22 12:33:41 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-12-18 13:18:28 -0500

clalancette gravatar image

It's important to add all of your dependencies to the package.xml. That does a few different things:

  1. For users who are building your package from source, it lets rosdep know which packages to install from the system.
  2. If you end up building your package on the ROS 2 buildfarm (https://build.ros2.org), it needs to be in there so that the dependencies are available when it is built.
  3. If you end up building your package on the ROS 2 buildfarm, it sets up the debian package dependencies properly so that apt-get install ros-foxy-<mypackage> installs all of the dependencies.

That being said, adding to the package.xml doesn't modify your environment at all. So it won't help your python package to "find" dependencies. Essentially if you can run python3 and import <dep>, then your package should be able to find it. Typically those are either from system packages, or through pip.

edit flag offensive delete link more

Comments

Sorry I'm still slightly confused. Just to make sure I understand... so in my case, I should add dynamixel_sdk to the package.xml... and since it is in package.xml... rosdep should be able to install it? I used pip to install the sdk, but I guess if someone else used rosdep, that would work?

infantasy gravatar image infantasy  ( 2020-12-18 13:30:14 -0500 )edit

The general idea with listing your dependencies in the package.xml is so that your users can just use rosdep to install the dependencies. At least for system packages (ones you can install with apt install), that's how it works. I'm not quite sure how pip packages work there, but I think it works in a similar way.

clalancette gravatar image clalancette  ( 2021-01-04 13:57:53 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-12-08 17:02:14 -0500

Seen: 2,061 times

Last updated: Dec 18 '20