"name 'serial' is not defined" Was muss ich anders machen? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

"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)

6th Jan 2021, 1:53 PM
TJ06 - avatar
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
6th Jan 2021, 3:11 PM
XXX - avatar
+ 2
Solution is to install package this way if you are doing it in sololearn playground https://code.sololearn.com/c1NjUr1lX2TS/?ref=app
6th Jan 2021, 2:22 PM
Abhay - avatar
+ 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.
6th Jan 2021, 3:20 PM
Mert Yazıcı
Mert Yazıcı - avatar