Como corrigir python-can can.exceptions.CanInterfaceNotImplementedError: The serial module is not installed

Problema

Você está usando a biblioteca python-can e recebe o seguinte erro:

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

Solução

A mensagem de erro é bem clara: Você precisa instalar o módulo serial. Você pode fazer isso via pip:

install_pyserial.sh
pip install pyserial

Check out similar posts by category: Python