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

How to use a PyPI dependency?

asked 2020-10-19 14:44:20 -0500

colllin gravatar image

updated 2020-10-20 16:57:26 -0500

I really need help connecting a few dots on this. I’ve only been working with Python for a few years, and I’m totally new to ROS2. I’ve been googling for hours and can’t find a thorough explanation anywhere.

I want to install and use a python package from PyPI, say some_special_package. I found that I can submit a PR to add the package to some kind of rosdep global registry, at which point I would expect rosdep resolve python-some_special_package to resolve it so that I can add an <exec_depend>python-some_special_package</exec_depend> to my project.xml file.

What if I just want to get something working right now on my own system? Let’s say that I followed this tutorial: https://index.ros.org/doc/ros2/Tutori... to create a couple simple nodes. Then I typed import some_special_package at the top of one of the python files. Now when I rosdep install ..., colcon build, source install/setup.bash, and finally ros2 run ..., I get a ModuleNotFoundError originating from the new line in my python file. What’s next? I must be missing something super simple. I tried creating a venv and installing the package myself. That doesn’t seem to be recognized.

I think the piece of information I’m missing is: where do my ROS nodes get their site packages from / where is the ros python path pointing to? (And how do I get custom packages there?)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2020-10-19 15:30:44 -0500

130s gravatar image

Disclaimer: I haven't used ROS2.

import some_special_package within my ros node. I rosdep installed, (skip) ran ros2 run my_pkg my_node, and I get a ModuleNotFoundError.

The one prints that error is Python, which is looking for a Python module. The name of a Python module can be different from the Python package that includes the module of your interest.

Assuming rosdep install part passed without errors, the PyPi package you wanted is likely installed (but make sure if that's the case. Depending on the option, rosdep ignores the error).

edit flag offensive delete link more

Comments

1

Hi @130s, thank you kindly for attempting to help me out. Are you trying to say that I might not have imported the correct module name? I copied and pasted this line from a python module that runs just fine outside of ROS, so I don’t believe that’s the issue. My question is really about how to get an external python dependency into ROS? I revised my question to try to clarify that I tried pip installing the package into a virtual env, but ROS doesn’t seem to pick this up. How do I get an external package installed into a place where my ROS node can find it?

colllin gravatar image colllin  ( 2020-10-20 17:01:36 -0500 )edit

I’m trying to go back to the beginning so someone can spell it out for me. I have a working ROS node written in Python. I want to import some_special_package and use that module in my python code. As soon as I add that import line, when I re-build and re-run the node, I get a ModuleNotFoundError (obviously — because I didn’t do anything to tell ROS or my system about this python module — I just typed its name into a file). How do I install this module so that ROS can see it, or inform ROS how to install it?

colllin gravatar image colllin  ( 2020-10-20 17:04:35 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-19 14:44:20 -0500

Seen: 463 times

Last updated: Oct 20 '20