Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ImportError: No module named serial" - after installing pyserial

Tags:

python

windows

I'm writing a project in python which should eventually running on LinkIt One IoT device.

I've written some test code to check whether I am able to connect between Arduino IDE to python (I am working with Pycharm).

the test code is:

import serial
import time

arduino = serial.Serial('COM1', 115200, timeout=.1)

time.sleep(1) #give the connection a second to settle

arduino.write("Hello from Python!")

while True:
    data = arduino.readline()
    if data:
        print data.rstrip('\n')

when I am running to code I am getting:

C:\Users\אורי\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/אורי/PycharmProjects/untitled2/test.py

Traceback (most recent call last): File "C:/Users/����/PycharmProjects/untitled2/test.py", line 1, in import serial ImportError: No module named serial

like image 439
Ori Halyo Avatar asked Apr 19 '18 08:04

Ori Halyo


1 Answers

how did you install your serial module? If you want to make sure It will be detected, go into your console

pip install serial

and run your code from the console too

python test.py # make sure your console is in the right folder path

or

find where the module is installed, something like "C:\Python27\Lib\site-packages"

import sys
sys.path.append("C:\Python27\Lib\site-packages") # this is where python stores modules, yours could be different 
import serial
like image 109
Peko Chan Avatar answered Nov 14 '22 23:11

Peko Chan