I want to receive data form an Xbee to an other Xbee which is connect to my pc (windows 10). But i can't import the xbee library needed. I install the librairy with :
pip install xbee
Here is my code :
import serial
from xbee import XBee
serial_port = serial.Serial('COM4', 9600)
xbee2 = XBee(serial_port)
while True:
try:
reponse = xbee2.wait_read_frame()
print (reponse)
except KeyboardInterrupt:
break
serial_port.close()
I took the code from : https://python-xbee.readthedocs.io/en/latest/
Here is the error:
Traceback (most recent call last):
File "C:\Users\mis\Desktop\xbee.py", line 2, in <module>
from xbee import XBee
File "C:\Users\mis\Desktop\xbee.py", line 2, in <module>
from xbee import XBee
ImportError: cannot import name 'XBee'
Could somebody help me, Thanks in advance
I think this is a simple one; looking at your error, it seems that the script you're working on is called xbee.py
.
The library you're trying to import is also called xbee
.
So, Python is getting a bit confused, it's trying to import XBee from the script you're working in I suspect (I think the module searching mechanism looks in the local folder first).
If you rename your script from xbee.py
to something else test_xbee.py
for example, you should be fine.