Python no module named serial

I have a problem with my python program. I wrote a program to get data (temperature) from arduino to my raspberry pi sqlite database. but it gives me an error in line4 (serial import) saying: "ImportError: No module named serial". I am using python3 and have already updated pyserial. I am new to python, so I am making some mistakes ...

#!/ussr/bin/python # -*- coding: utf-8 -*- import serial import datetime import sqlite3 as lite import sys import time ser = serial.Serial('/dev/ttyACM1', 9600, timeout=1) ser.open() count = 0 con = lite.connect('realtime_data.db') try: while 1: indata = ser.readline() current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") count = count + 1 print (count) with con: cur = con.cursor() cur.execute("INSERT INTO Temperatures VALUES( ?, ?, ? )", (count, current_time, indata)) if count > 100: cur.execute("DELETE FROM Temperatures") count = 0 # time.sleep(3) #upload to database every 5 seconds except KeyboardInterrupt: ser.close() 
+7
python database sqlite
source share
2 answers

Here is a question about How to install pip with Python 3? . After that, you can use pip to install pyserial , compatible with python-3.x, as follows:

 $ sudo pip3 install pyserial 

Here is a doc on how to install pyserial using its python-3.x compatible source code

PS: If your platform has both python-2.x and python-3.x, for example Arch Linux, when you want to install some packages, you should be careful to choose which version of python should be compatible with and then use pip2 or pip3 to get and install these packages.

+15
source share

If the file name that you saved matches the name of the module, it will result in an error. For example, if your file name is "serial.py" and you have serial import, then it will first check serial.py for the methods you specify.

+1
source share

All Articles