ESP32 compiling issues with linux

I am getting the following error when I try to compile to any esp32 board:
Arduino: 1.8.19 (Linux), Board: "LOLIN S2 Mini, Enabled, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), None, Disabled"

Traceback (most recent call last):
File "/home/###/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool.py", line 31, in
import esptool
File "/home/###/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool/init.py", line 41, in
from esptool.cmds import (
File "/home/###/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool/cmds.py", line 12, in
import zlib
ModuleNotFoundError: No module named 'zlib'
exit status 1
Error compiling for board LOLIN S2 Mini.

I have install pyenv to change the global python version to see if that was the issue, switching between 2.4 and 3.12. I also get the same issue on Arduino 2.2.
The esp32 board manager has been updated to 2.0.14
Compiling to an Uno does not have this issue.
I'm not sure if this is an arduino issue, a python issue, or something else.
Any help would be appreciated.

Hi @mrmike88

Were you getting the exact same "ModuleNotFoundError: No module named 'zlib'" error message before you did that, or was the error message different?

From some quick research, it appears this specific error message occurs when using an incomplete installation of Python. The ESP32 boards platform provides its own complete installation of Python that is used when you are compiling and uploading to the ESP32 boards so I would not expect this error message to occur when that installation of Python is in use.

I'm going to ask you to post the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences...(or Arduino > Preferences... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the "OK" button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. After the compilation fails you'll see a button on the right side of the orange bar in Arduino IDE: Copy error messages. Click that button.
    This copies the full output to the clipboard.
  6. Open a forum reply here by clicking the "Reply" button.
  7. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  8. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  9. Move the cursor outside of the code block markup before you add any additional text to your reply.
  10. Click the "Reply" button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the "Upload" icon (image) on the post composer toolbar:
    Upload icon on toolbar
    A dialog will open.
  6. In the dialog, select the .txt file you saved.
  7. Click the "Open" button.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

Here it is. Thanks

Arduino: 1.8.19 (Linux), Board: "LOLIN S2 Mini, Enabled, Disabled, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), None, Disabled"











/home/cnc/arduino-1.8.19/arduino-builder -dump-prefs -logger=machine -hardware /home/cnc/arduino-1.8.19/hardware -hardware /home/cnc/.arduino15/packages -tools /home/cnc/arduino-1.8.19/tools-builder -tools /home/cnc/arduino-1.8.19/hardware/tools/avr -tools /home/cnc/.arduino15/packages -built-in-libraries /home/cnc/arduino-1.8.19/libraries -libraries /home/cnc/Arduino/libraries -fqbn=esp32:esp32:lolin_s2_mini:CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,PartitionScheme=default,DebugLevel=none,EraseFlash=none -vid-pid=303A_80C2 -ide-version=10819 -build-path /tmp/arduino_build_459708 -warnings=all -build-cache /tmp/arduino_cache_616689 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-esp-elf-gdb.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.xtensa-esp-elf-gdb-11.2_20220823.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.dfu-util.path=/home/cnc/.arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.dfu-util-0.11.0-arduino5.path=/home/cnc/.arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.mkspiffs.path=/home/cnc/.arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mkspiffs-0.2.3.path=/home/cnc/.arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mklittlefs.path=/home/cnc/.arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.mklittlefs-3.0.0-gnu12-dc7f933.path=/home/cnc/.arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.esptool_py.path=/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.esptool_py-4.5.1.path=/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.riscv32-esp-elf-gdb.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.riscv32-esp-elf-gdb-11.2_20220823.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.openocd-esp32.path=/home/cnc/.arduino15/packages/esp32/tools/openocd-esp32/v0.12.0-esp32-20230419 -prefs=runtime.tools.openocd-esp32-v0.12.0-esp32-20230419.path=/home/cnc/.arduino15/packages/esp32/tools/openocd-esp32/v0.12.0-esp32-20230419 -prefs=runtime.tools.riscv32-esp-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -verbose /home/cnc/Arduino/dehydrator/dehydrator.ino
/home/cnc/arduino-1.8.19/arduino-builder -compile -logger=machine -hardware /home/cnc/arduino-1.8.19/hardware -hardware /home/cnc/.arduino15/packages -tools /home/cnc/arduino-1.8.19/tools-builder -tools /home/cnc/arduino-1.8.19/hardware/tools/avr -tools /home/cnc/.arduino15/packages -built-in-libraries /home/cnc/arduino-1.8.19/libraries -libraries /home/cnc/Arduino/libraries -fqbn=esp32:esp32:lolin_s2_mini:CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,PartitionScheme=default,DebugLevel=none,EraseFlash=none -vid-pid=303A_80C2 -ide-version=10819 -build-path /tmp/arduino_build_459708 -warnings=all -build-cache /tmp/arduino_cache_616689 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-esp-elf-gdb.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.xtensa-esp-elf-gdb-11.2_20220823.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.dfu-util.path=/home/cnc/.arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.dfu-util-0.11.0-arduino5.path=/home/cnc/.arduino15/packages/arduino/tools/dfu-util/0.11.0-arduino5 -prefs=runtime.tools.mkspiffs.path=/home/cnc/.arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mkspiffs-0.2.3.path=/home/cnc/.arduino15/packages/esp32/tools/mkspiffs/0.2.3 -prefs=runtime.tools.mklittlefs.path=/home/cnc/.arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.mklittlefs-3.0.0-gnu12-dc7f933.path=/home/cnc/.arduino15/packages/esp32/tools/mklittlefs/3.0.0-gnu12-dc7f933 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s2-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s2-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.esptool_py.path=/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.esptool_py-4.5.1.path=/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1 -prefs=runtime.tools.riscv32-esp-elf-gdb.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.riscv32-esp-elf-gdb-11.2_20220823.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gdb/11.2_20220823 -prefs=runtime.tools.openocd-esp32.path=/home/cnc/.arduino15/packages/esp32/tools/openocd-esp32/v0.12.0-esp32-20230419 -prefs=runtime.tools.openocd-esp32-v0.12.0-esp32-20230419.path=/home/cnc/.arduino15/packages/esp32/tools/openocd-esp32/v0.12.0-esp32-20230419 -prefs=runtime.tools.riscv32-esp-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.riscv32-esp-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/riscv32-esp-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -prefs=runtime.tools.xtensa-esp32s3-elf-gcc-esp-2021r2-patch5-8.4.0.path=/home/cnc/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/esp-2021r2-patch5-8.4.0 -verbose /home/cnc/Arduino/dehydrator/dehydrator.ino
Using board 'lolin_s2_mini' from platform in folder: /home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14
Using core 'esp32' from platform in folder: /home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14
bash -c "[ ! -f \"/home/cnc/Arduino/dehydrator\"/partitions.csv ] || cp -f \"/home/cnc/Arduino/dehydrator\"/partitions.csv \"/tmp/arduino_build_459708\"/partitions.csv"
bash -c "[ -f \"/tmp/arduino_build_459708\"/partitions.csv ] || [ ! -f \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14/variants/lolin_s2_mini\"/partitions.csv ] || cp \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14/variants/lolin_s2_mini\"/partitions.csv \"/tmp/arduino_build_459708\"/partitions.csv"
bash -c "[ -f \"/tmp/arduino_build_459708\"/partitions.csv ] || cp \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14\"/tools/partitions/default.csv \"/tmp/arduino_build_459708\"/partitions.csv"
bash -c "[ -f \"/home/cnc/Arduino/dehydrator\"/bootloader.bin ] && cp -f \"/home/cnc/Arduino/dehydrator\"/bootloader.bin \"/tmp/arduino_build_459708\"/dehydrator.ino.bootloader.bin || ( [ -f \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14/variants/lolin_s2_mini\"/bootloader.bin ] && cp \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14/variants/lolin_s2_mini\"/bootloader.bin \"/tmp/arduino_build_459708\"/dehydrator.ino.bootloader.bin || python3 \"/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1\"/esptool.py --chip esp32s2 elf2image --flash_mode dio --flash_freq 80m --flash_size 4MB -o \"/tmp/arduino_build_459708\"/dehydrator.ino.bootloader.bin \"/home/cnc/.arduino15/packages/esp32/hardware/esp32/2.0.14/tools/sdk/esp32s2\"/bin/bootloader_qio_80m.elf )"
Traceback (most recent call last):
  File "/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool.py", line 31, in <module>
    import esptool
  File "/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool/__init__.py", line 41, in <module>
    from esptool.cmds import (
  File "/home/cnc/.arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool/cmds.py", line 12, in <module>
    import zlib
ModuleNotFoundError: No module named 'zlib'
exit status 1
Error compiling for board LOLIN S2 Mini.

I was wrong about this. I was thinking of the ESP8266 boards platform. The ESP32 boards platform only provides its own installation of Python when used on a Windows machine. On Linux machines it uses the system installation of Python.

So it seems your system installation of Python is somehow incomplete. Unfortunately I don't have any specific advice for solving this. Hopefully one of the other forum helpers can provide more effective assistance.

I did find some discussions of the problem and reports of various solutions on Stack Exchange, but none of them stood out to me as a canonical resource for me to point out to you. You will find them if you do a Google search for "ModuleNotFoundError: No module named 'zlib'" though.

Any solution I found with the googles did not rectify this. I am going to re-build the system with a fresh copy of debian, and try again. Thank for the help.

1 Like

I ended up installing python3-venv to get the program working.

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