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
AttributeError: module 'XBee' has no attribute 'XBee'

This error says import XBee succeeded, but Python didn't find anything in that module called XBee. This is strange because the XBee.py file you posted definitely has a class XBee. I would try debugging this by adding print statements to see what module was imported.

if __name__ == "__main__":
    # Figure out what file python imported for the XBee module
    import inspect
    print(inspect.getsourcefile(XBee))

    # Print the attributes that are available on the XBee module
    print(dir(XBee))

    # xbee = XBee.XBee("/dev/ttyUSB0")
    # mqs_xbee()

That will give useful info for debugging the issue.

Edit Thanks for posting the CMakeLists.txt output!

It seems mqs_xbee.py expects to be able to import XBee.py installed adjacent to it, which is an assumption that doesn't hold in all circumstances in ROS Noetic. catkin_install_python() is for installing scripts that are meant to be run directly, not imported. I would recommend solving this by installing the code in XBee.py as a python package.

This means adding catkin_python_setup() to your CMakeLists.txt, a setup.py, and maybe making a folder with an __init__.py. See the catkin documentation for more info.

For a practical example of a package that has both Python scripts and modules check out urdf_parser_py.

Original answer below


AttributeError: module 'XBee' has no attribute 'XBee'

This error says import XBee succeeded, but Python didn't find anything in that module called XBee. This is strange because the XBee.py file you posted definitely has a class XBee. I would try debugging this by adding print statements to see what module was imported.

if __name__ == "__main__":
    # Figure out what file python imported for the XBee module
    import inspect
    print(inspect.getsourcefile(XBee))

    # Print the attributes that are available on the XBee module
    print(dir(XBee))

    # xbee = XBee.XBee("/dev/ttyUSB0")
    # mqs_xbee()

That will give useful info for debugging the issue.