简体   繁体   English

AttributeError: 模块 'serial' 没有属性 'Serial'

[英]AttributeError: module 'serial' has no attribute 'Serial'

from serial import serial
joystick = serial.Serial("COM3", 9600)
joystick_x = joystick.write('0')
if joystick_x==1023:
    print("Right")
elif joystick_x != 1023:
    print("Not right");

and I received error message:我收到了错误信息:

Traceback (most recent call last):
  File "C:/Users/Mine_science/Desktop/snu6/산출물/arduino.py", line 1, in <module>
    from serial import serial
  File "C:\Users\Mine_science\AppData\Local\Programs\Python\Python35\lib\site-packages\serial\serial\__init__.py", line 13, in <module>
    from serial.serialutil import *
ImportError: No module named 'serial.serialutil'

also Can you give me some advices to get each pin.你也能给我一些建议来获得每个别针吗?

I installed serial library using "pip3 install serial" and get the same error even calling the library using "import serial".我使用“pip3 install serial”安装了串行库,即使使用“import serial”调用库也得到同样的错误。 Then I found that if first UNINSTALL serial:然后我发现如果先UNINSTALL串口:

pip3 uninstall serial

and then install pyserial:然后安装pyserial:

pip3 install pyserial

fixed the problem for python 3.修复了python 3的问题。

Looking at the documentation it looks like you only need to do查看文档看起来你只需要做

import serial

instead of代替

from serial import serial

http://pyserial.readthedocs.io/en/latest/shortintro.html http://pyserial.readthedocs.io/en/latest/shortintro.html

uninstalling python and pyserial package completely and then完全卸载python和pyserial包然后

installing python(python 3 in my case) back -安装python(在我的例子中是python 3)回来 -

for all users and add Paths correctly对于所有用户并正确添加路径

and then use然后使用

pip3 for installing pyserial pip3 用于安装 pyserial

fixed all my issues解决了我所有的问题

I was getting the same error, but what works for me was:我遇到了同样的错误,但对我有用的是:

  1. uninstall serial: pip3 uninstall serial卸载串口: pip3 uninstall serial
  2. uninstall pyserial: pip3 uninstall pyserial卸载pyserial: pip3 uninstall pyserial
  3. reinstall a previous version of pyserial: pip3 install pyserial==3.3 (I had 3.5 version)重新安装以前版本的 pyserial: pip3 install pyserial==3.3 (我有 3.5 版本)

I wanted to use minimalmodbus and got the same error message as in the title of this post.我想使用 minimalmodbus 并收到与本文标题中相同的错误消息。 What worked for me:对我有用的是:

sudo apt install python-is-python3

Apparently there was some confusion between python 2 and 3 and python-is-python3 resolved it.显然 python 2 和 3 之间存在一些混淆,python-is-python3 解决了它。

I found that the below worked when I encountered this same problem:当我遇到同样的问题时,我发现以下方法有效:

from serial import *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM