Home/Support/Support Forum/why do I get a NameError: name 'AF_XBEE' is not defined
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

why do I get a NameError: name 'AF_XBEE' is not defined

+1 vote
I am trying to setup a local Digi Python environment to run my unit tests locally. Here is the quick summary of my steps:

$ virtualenv digiTestEnv
$ source digiTestEnv/bin/activate
$ digiTestEnv/bin/pip install xbee

everything good so far...

$ python
>>> import xbee
>>> from socket import *
>>> sd = socket(AF_XBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)

here I get...

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'AF_XBEE' is not defined
asked Mar 31, 2015 in Python by Mishka201 New to the Community (2 points)
I'm just setting up a similar project for the first time and am getting the same thing. Did you figure it out?

Please log in or register to answer this question.

1 Answer

0 votes
Yes, here are the updated steps that worked for me to get past this error (NOTE: you will need to download a copy of the py-for-PC source code):

1) From the command line (myDigiPython can be whatever you want):

$ virtualenv myDigiPython
$ source myDigiPython/bin/activate
$ pip install xbee

2) Once the XBee module is successfully installed, replace the zigbee.py in myDigiPython/lib/python2.7/site-packages/xbee with the one from zigbee_py-for-PC

3) In order for the Digi socket extensions to work, you will need to modify the socket.py that comes with standard Python2.7 library. Open socket.py and change the following lines:

from:

family = property(lambda self: self._sock.family, doc="the socket family")
type = property(lambda self: self._sock.type, doc="the socket type")
proto = property(lambda self: self._sock.proto, doc="the socket protocol")

to:

family = property(lambda self: self._sock.family, lambda self, value: setattr(self, '_socketobject._sock.family', value), doc="the socket family")
type = property(lambda self: self._sock.type, lambda self, value: setattr(self, '_socketobject._sock.type', value), doc="the socket type")
proto = property(lambda self: self._sock.proto, lambda self, value: setattr(self, '_socketobject._sock.proto', value), doc="the socket protocol")
answered May 26, 2015 by Mishka201 New to the Community (2 points)
Hi Mishka,
I'm trying to run xbee programmes by local python too, and I face the same problem with you. I've followed your step, but the problem hasn't fixed. It still shows: NameError: name 'AF_XBEE' is not defined.:(
Can I ask what's the "py-for-PC source code"? and the Xbee file which install in virtualenv is download through python.com?
Thank you so much.
...