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

Revision history [back]

click to hide/show revision 1
initial version

To my surprise, in my_script.py, I can import from the package turtlesim, like from turtlesim.msg import Pose, without getting errors. So, turtlesim seems to be part of my dependencies. Why is that?

turtlesim is not part of your dependencies, as it isn't part of the list that rospack depends shows, is not listed in your package.xml nor your CMakeLists.txt. Questions #q217475 and #q215059 can perhaps provide some more insight into how package dependencies are encoded and resolved by the various pieces of infrastructure.

As to why you can import the turtlesim Python module, that is because it is on the PYTHONPATH as soon as you source the appropriate setup.(ba|z)sh. If it's installed from a deb, you can find all ROS packages that provide Python modules under /opt/ros/$distro/lib/python2.7/dist-packages. As Python does not need any linking or compilation, just placing a module on its search path is enough to be able to import it.

To my surprise, in my_script.py, I can import from the package turtlesim, like from turtlesim.msg import Pose, without getting errors. So, turtlesim seems to be part of my dependencies. Why is that?

turtlesim is not part of your dependencies, as it isn't part of in the list that rospack depends shows, is not listed in your package.xml nor your CMakeLists.txt. Questions #q217475 and #q215059 can perhaps provide some more insight into how package dependencies are encoded and resolved by the various pieces of infrastructure.

As to why you can import the turtlesim Python module, that is because it is on the PYTHONPATH as soon as you source the appropriate setup.(ba|z)sh. If it's installed from a deb, you can find all ROS packages that provide Python modules under /opt/ros/$distro/lib/python2.7/dist-packages. As Python does not need any linking or compilation, just placing a module on its search path is enough to be able to import it.

To my surprise, in my_script.py, I can import from the package turtlesim, like from turtlesim.msg import Pose, without getting errors. So, turtlesim seems to be part of my dependencies. Why is that?

turtlesim is not part of your dependencies, as it isn't in the list that rospack depends shows, is not listed in your package.xml nor your CMakeLists.txt. Questions #q217475 and #q215059 can perhaps provide some more insight into how package dependencies are encoded and resolved by the various pieces of infrastructure.

As to why you can import the turtlesim Python module, that is because it is on the PYTHONPATH as soon as you source the appropriate setup.(ba|z)sh. If it's installed from a deb, you can find all ROS packages that provide Python modules under /opt/ros/$distro/lib/python2.7/dist-packages. As Python does not need any linking or compilation, just placing a module on its search path is enough to be able to import it.


Edit:

When I said " seems to be part of my dependencies" I didn't mean that it's part of my dependencies, in fact, I said, "seems to".

And I just made it explicit that it isn't.

Do you ever assume that a package is under /opt/ros/$distro/lib/python2.7/dist-packages or do you always prefer to specify the dependency in the package.xml file, even if you have the same package under /opt/ros/$distro/lib/python2.7/dist-packages?

Never assume anything. You cannot assume anything about the state of the system that your package / script(s) will be run on, and your next user might have a full install of "all" ROS pkgs, or have a very barren installation with just ros_comm and some dependencies. Always make your dependencies explicit so that you're users know what they should provide (but then use rosdep to take care of that for you, #q252478).

To my surprise, in my_script.py, I can import from the package turtlesim, like from turtlesim.msg import Pose, without getting errors. So, turtlesim seems to be part of my dependencies. Why is that?

turtlesim is not part of your dependencies, as it isn't in the list that rospack depends shows, is not listed in your package.xml nor your CMakeLists.txt. Questions #q217475 and #q215059 can perhaps provide some more insight into how package dependencies are encoded and resolved by the various pieces of infrastructure.

As to why you can import the turtlesim Python module, that is because it is on the PYTHONPATH as soon as you source the appropriate setup.(ba|z)sh. If it's installed from a deb, you can find all ROS packages that provide Python modules under /opt/ros/$distro/lib/python2.7/dist-packages. As Python does not need any linking or compilation, just placing a module on its search path is enough to be able to import it.


Edit:

When I said " seems to be part of my dependencies" I didn't mean that it's part of my dependencies, in fact, I said, "seems to".

And I just made it explicit that it isn't.

Do you ever assume that a package is under /opt/ros/$distro/lib/python2.7/dist-packages or do you always prefer to specify the dependency in the package.xml file, even if you have the same package under /opt/ros/$distro/lib/python2.7/dist-packages?

Never assume anything. You cannot assume anything about the state of the system that your package / script(s) will be run on, and on: your next user might have a full install of "all" ROS pkgs, or have a very barren installation with just ros_comm and some dependencies. Always make your dependencies explicit so that you're your users know what they should provide (but then use rosdep to take care of that for you, #q252478).