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:
Does your package have <depend package="foo"/> in the manifest.xml file?
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
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.
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...
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named foo
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:
Does your file include the correct call to:
import roslib; roslib.load_manifest('your_package_name')
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
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:
before you call gtk.main().