When compiling sketch for esp32 have ModuleNotFoundError 'serial'

Hi, when i compiling sketch for esp32 on Ubuntu20.04 have error below.

$ arduino-cli compile --fqbn esp32:esp32:m5stack_cores3

Traceback (most recent call last):
  File "/home/inchoxd/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool.py", line 34, in <module>
    import esptool
  File "/home/inchoxd/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/__init__.py", line 41, in <module>
    from esptool.cmds import (
    ...<24 lines>...
    )
  File "/home/inchoxd/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/cmds.py", line 14, in <module>
    from .bin_image import ELFFile, ImageSegment, LoadFirmwareImage
  File "/home/inchoxd/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/bin_image.py", line 14, in <module>
    from .loader import ESPLoader
  File "/home/inchoxd/.arduino15/packages/esp32/tools/esptool_py/4.6/esptool/loader.py", line 30, in <module>
    import serial
ModuleNotFoundError: No module named 'serial'

Used platform Version Path
esp32:esp32   3.0.5   /home/inchoxd/.arduino15/packages/esp32/hardware/esp32/3.0.5
Error during build: exit status 1

esptool and pyserial are already installed from pip, serial is not install.

When I run python -c "import serial", it was no error.
Plese tell me how to solve it.

Hi @inchoxd. Try running this command:

python3 -m pip install pyserial

The esp32:esp32 platform uses python3, not python, so your test using python was not conclusive proof that the pyserial package is available for use by python3.

1 Like

Alternate suggestion for Debian/Ubuntu

sudo apt install python3-serial
1 Like

Hi @ptillisch. Tried your posts, it was solved. THX.
My python enviroment is pyenv, so it was little defficult. What I have done below.

  1. python3 -m pip install pyserial but externally-managed-environment error occureded.
  2. python3 -m pip install pyserial --break-system-package it was completely install and without error when run arduino-cli compile ....

You are welcome. I'm glad it is working now. Thanks for taking the time to post an update with your findings!

Regards, Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.