如果我要执行pyserial,为什么会给出错误消息,但如果我在shell中执行相同的操作,为什么不给出错误消息

时间:2019-11-03 18:14:34

标签: pyserial python-3.7.4

有人知道为什么我在运行以下代码时在python中收到以下错误消息吗?如果我在Shell中运行它,则不会发生。 picture of the problem

代码:

import serial
ser = serial.Serial("COM6", baudrate = 9600, timeout=1)

while 1:
    arduinoData = ser.readline().decode('ascii')
    print(arduinoData)

错误消息:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
================= RESTART: C:\Users\tiesv\Desktop\serial.py =================
Traceback (most recent call last):
  File "C:\Users\tiesv\Desktop\serial.py", line 1, in <module>
    import serial
  File "C:\Users\tiesv\Desktop\serial.py", line 2, in <module>
    ser = serial.Serial("COM6", baudrate = 9600, timeout=1)
AttributeError: module 'serial' has no attribute 'Serial'
>>> 

先谢谢您

0 个答案:

没有答案