0
"name 'serial' is not defined" Was muss ich anders machen?
from serial import Serial port = serial.Serial("/dev/ttyUSB0", 9600); port.open(); while true: daten = port.readline(); print (daten)
4 Answers
+ 5
Tom Jennes after you install the package following Abhay and Kode Krasher 's answer, your code will still not work.
Your first line
`from serial import Serial`
imports the `Serial` class, not the `serial` module itself. So the line
port = serial.Serial.....
Is invalid as `serial` does not exist.
To fix the code change the first line to
import serial
+ 2
Solution is to install package this way if you are doing it in sololearn playground
https://code.sololearn.com/c1NjUr1lX2TS/?ref=app
+ 2
If you already have the package and it still doesn't work, it's probably because you only import Serial class from the package. Removing "serial." from third line or importing "serial" instead of "serial.Serial" should fix the error.