Wie man python-can can.exceptions.CanInterfaceNotImplementedError: The serial module is not installed behebt

Problem

Sie verwenden die python-can-Bibliothek und erhalten den folgenden Fehler:

error_message.txt
You won't be able to use the slcan can backend without the serial module installed!
Traceback (most recent call last):
  File "/home/uli/TestCAN.py", line 10, in <module>
    bus = can.interface.Bus(bustype='slcan', channel=slcan_device, bitrate=baud_rate)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uli/.pyenv/versions/3.11.9/lib/python3.11/site-packages/can/util.py", line 379, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/uli/.pyenv/versions/3.11.9/lib/python3.11/site-packages/can/interface.py", line 135, in Bus
    bus = cls(channel, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/uli/.pyenv/versions/3.11.9/lib/python3.11/site-packages/can/interfaces/slcan.py", line 98, in __init__
    raise CanInterfaceNotImplementedError("The serial module is not installed")
can.exceptions.CanInterfaceNotImplementedError: The serial module is not installed

Lösung

Die Fehlermeldung ist ziemlich eindeutig: Sie müssen das serial-Modul installieren. Sie können dies über pip tun:

install_pyserial.sh
pip install pyserial

Check out similar posts by category: Python