I would like to handle my xbee with raspberry pi via Python. I install xbee with this command:

pip install xbee

And I try to use this example code:

#! /usr/bin/python

# Import and init an XBee device
from xbee import XBee,ZigBee
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)

# Use an XBee 802.15.4 device
# To use with an XBee ZigBee device, replace with:
#xbee = ZigBee(ser)
xbee = XBee(ser)

# Set remote DIO pin 2 to low (mode 4)


This code is from this site: Python xbee

When I try to execute this code I got this error:

ImportError: cannot import name Xbee

When I type this command:

pip search xbee

I see the Xbee module:

egenix-mx-base            - eGenix mx Base Distribution for Python -
                            mxDateTime, mxTextTools, mxProxy, mxTools,
                            mxBeeBase, mxStack, mxQueue, mxURL, mxUID
XBee                      - Python tools for working with XBee radios
  INSTALLED: 2.1.0 (latest)
hachi                     - XBee API
txXBee                    - XBee Protocol for Twisted
pyctu                     - A curses interface to configure xbees

What am I doing wrong? How to import the xbee module to python?

1 Answer 1


Judging by your error message, "ImportError: cannot import name Xbee", it looks like you might have typed "from xbee import Xbee" and not "from xbee import XBee".

  • Nicely spotted! @David Always keep in mind that python (and many other scripting and programming languages) are case sensitive, thus Xbee and XBee are two different things.
    – Ghanima
    Commented Sep 23, 2014 at 20:08
  • 1
    Couldn't resist it: you mean to say 'Xbee or not XBee: that is the question....' ? ;-)
    – monojohnny
    Commented Feb 28, 2015 at 23:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.