简体   繁体   中英

MinimalModbus import error => AttributeError: module 'serial' has no attribute 'Serial'

I'm trying to use minimalmodbus library but i cannot import it because i get the error

File "testmodbus.py", line 3, in <module>
    import minimalmodbus
  File "/usr/local/lib/python3.7/dist-packages/minimalmodbus.py", line 61, in <module>
    _serialports: Dict[str, serial.Serial] = {}  # Key: port name, value: port instance
AttributeError: module 'serial' has no attribute 'Serial'

I have installed it via pip3 install minimalmodbus. I'm using python 3.7.3 and do not know what can i do, if it is important i have pyserial version 3.4

This might be caused by many things.

  1. How did you install minimalmodbus? Is it with pip install minimalmodbus ? manual install? copy minimalmodbus.py file to your project? or some other way? Knowing this would help figuring out if the installation of minimalmodbus and its dependencies is properly done.
  2. What is the output of python -m pip freeze | grep pyserial python -m pip freeze | grep pyserial ? If it shows something like pyserial==3.5 it means that pyserial (the library that provides the serial package containing the serial.Serial class in your error) is installed in your python environment.
  3. Do you have a file named serial.py on your python path (or a folder named serial possibly with a file __init__.py in it)? It may be that python is trying to import from this file instead of the pyserial package. If so try to rename this file/folder and then use minimalmodbus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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