[Documentation] [TitleIndex] [WordIndex

Import Issues

My Python package/module doesn't appear to export

By default, your ROS Package will export your_package/src on the PYTHONPATH. If you wish to export files that aren't in this location, you can add an <export> property to your manifest.xml. See the manifest.xml documentation for more details.

import foo.bar fails (i.e failure to import submodule)

If you're trying to import a submodule, e.g. foo.bar (the bar module in foo), there are a couple common errors:

  1. Does your package have <depend package="foo"/> in the manifest.xml file?

  2. Is foo missing an __init__.py file? In Python, in order to create submodules, you have to have an __init__.py in a directory to mark it as a module, e.g.

    foo/
     |-src/
        |-foo/
           __init__.py
           bar.py

Ctrl-C issues

Error: Node doesn't respond to Ctrl-C

Code written using rospy needs to regularly check for rospy.is_shutdown(), or it should call rospy.spin() from the Main Thread.

For example, this is bad code:

while True:
    pub.publish(msg)
    rospy.sleep(1.0)

This is good code:

while not rospy.is_shutdown():
    pub.publish(msg)
    rospy.sleep(1.0)

If you don't need to publish anything (e.g. your Node just subscribes or provides a Service), you can instead just call rospy.spin(), which does nothing, except for waiting for an exit signal.

Import errors

Error: No module named roslib

This probably means that your PYTHONPATH is not configured. Please make sure that your PYTHONPATH includes $ROS_ROOT/core/roslib/src.

Error: No module named...

The ROS Python client libraries do a lot of the work for you to set your PYTHONPATH, but there are a couple of rules you need to follow to have this magic work correctly:

  1. Does your file include the correct call to:

    import roslib; roslib.load_manifest('your_package_name')
  2. If the package you are attempting to import is a ROS Package, does your manifest.xml include the correct <depend package="foo"/> tag?

  3. If the package you are attempting to import is a non-ROS, system-installed dependency (e.g. wxWidgets), has it been properly installed? One way to test this is to run rosdep install your_package

GUI Issues

GTK: Threads don't work

If you're using rospy with GTK, you will need to use GTK's calls to enable proper Python threading. In particular, multithreaded applications using the Python threading module won't work properly unless you call:

gtk.gdk.threads_init()

before you call gtk.main().


2024-12-21 18:31