Don't understand reason for Import error: cannot import name 'Serial' from 'serial'

Don't understand reason for Import error: cannot import name 'Serial' from 'serial'

正如标题所示,我在使用 pyserial 模块时遇到错误。

我正在使用以下代码

from serial import Serial
ser = serial.Serial()
ser.baudrate = 115200
ser.port = 'COM3'

并且在我 运行 代码时出现以下错误:

ImportError: cannot import name 'Serial' from 'serial' 
(C:\Users\OPlim\AppData\Local\Programs\Python\Python37-32\lib\site- 
packages\serial\__init__.py)

我的文件名为 EASGLE_test.py,所以我知道它并没有尝试 import 本身,但我不知道出了什么问题。

这应该有效:

import serial
ser = serial.Serial()
ser.baudrate = 115200
ser.port = 'COM3'

如果它不在你的命令中 运行: pip install pyserial

Here 快速查看文档示例

您正在从序列号导入序列号

from serial import Serial
ser = serial.Serial()

将代码更改为:

import serial
ser = serial.Serial()

更新到 python 3.9 运行 pip install pyserial 再次。