Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named serial

Tags:

python

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.

like image 276
Amber.G Avatar asked Oct 21 '15 18:10

Amber.G


People also ask

What is serial module in Python?

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.

How do I know if PySerial is installed?

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.


1 Answers

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.

like image 164
Hosack Avatar answered Sep 22 '22 19:09

Hosack