and I got a question when I run my Python code.
I installed Python 2.7 on Windows 7, bit 64. I got an error "No module named serial" when I compiled my code:
import serial ser = serial.Serial("COM5", 9600) ser.write("Hello world") x = ser.readline() print(x)
I tried many ways to crack this problem, such as installed Canopy to setup virtual environment, make sure 'pip' is there, no Python v 3.x installed. But still cannot get it out.
Any advice would be appreciated.
This module encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named “serial” automatically selects the appropriate backend.
To check that it is installed, start Pyzo and at the command prompt type in: import serial If it just gives you another >>> prompt, all is good.
Serial is not included with Python. It is a package that you'll need to install separately.
Since you have pip installed you can install serial from the command line with:
pip install pyserial
Or, you can use a Windows installer from here. It looks like you're using Python 3 so click the installer for Python 3.
Then you should be able to import serial as you tried before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With