Error running Platformio / ESPIDF on Apple M1 Mac

I am setting VSCode/Platformio on a mac 13.2.1 M1 silicon. This is an installation from scratch so all software is a download of latest versions. When I try to build an ESP32 project I get the error below. Any suggestion how to fix it?

Platformio.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
monitor_speed = 115200
debug_tool=esp-prog
upload_speed=921600
user@Users-MacBook-Air platformio % pio system info
--------------------------  -------------------------------------------
PlatformIO Core             6.1.6
Python                      3.9.6-final.0
System Type                 darwin_arm64
Platform                    macOS-13.2.1
File System Encoding        utf-8
Locale Encoding             UTF-8
PlatformIO Core Directory   /Users/user/.platformio
PlatformIO Core Executable  /Users/user/.platformio/penv/bin/platformio
Python Executable           /Users/user/.platformio/penv/bin/python
Global Libraries            0
Development Platforms       1
Tools & Toolchains          8
--------------------------  -------------------------------------------

Build log:

Executing task: platformio run 

Processing esp32dev (platform: espressif32; board: esp32dev; framework: espidf)
------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.0.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50000.0 (5.0.0) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40400.0 (4.4.0) 
 - tool-ninja @ 1.9.0 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-xtensa-esp32 @ 11.2.0+2022r1
Reading CMake configuration...
-- Building ESP-IDF components for target esp32
-- Configuring incomplete, errors occurred!
See also "/Users/user/projects/ble_stepper_motor_analyzer/repo/platformio/.pio/build/esp32dev/CMakeFiles/CMakeOutput.log".

fatal: not a git repository (or any of the parent directories): .git
CMake Error at /Users/user/.platformio/packages/framework-espidf/tools/cmake/build.cmake:519 (message):
  Traceback (most recent call last):

    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/requests/compat.py", line 11, in <module>
      import chardet

  ModuleNotFoundError: No module named 'chardet'

  

  During handling of the above exception, another exception occurred:

  

  Traceback (most recent call last):

    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/idf_component_manager/prepare_components/__main__.py", line 4, in <module>
      from .prepare import main
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/idf_component_manager/prepare_components/prepare.py", line 18, in <module>
      from ..core import ComponentManager
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/idf_component_manager/core.py", line 17, in <module>
      import requests
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/requests/__init__.py", line 45, in <module>
      from .exceptions import RequestsDependencyWarning
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/requests/exceptions.py", line 9, in <module>
      from .compat import JSONDecodeError as CompatJSONDecodeError
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/requests/compat.py", line 13, in <module>
      import charset_normalizer as chardet
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/__init__.py", line 24, in <module>
      from .api import from_bytes, from_fp, from_path
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/api.py", line 5, in <module>
      from .cd import (
    File "/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/cd.py", line 9, in <module>
      from .md import is_suspiciously_successive_range

  ImportError:
  dlopen(/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/md.cpython-39-darwin.so,
  0x0002): tried:
  '/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/md.cpython-39-darwin.so'
  (mach-o file, but is an incompatible architecture (have 'arm64', need
  'x86_64')),
  '/System/Volumes/Preboot/Cryptexes/OS/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/md.cpython-39-darwin.so'
  (no such file),
  '/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/charset_normalizer/md.cpython-39-darwin.so'
  (mach-o file, but is an incompatible architecture (have 'arm64', need
  'x86_64'))

Call Stack (most recent call first):
  /Users/user/.platformio/packages/framework-espidf/tools/cmake/project.cmake:440 (idf_build_process)
  CMakeLists.txt:3 (project)


I think we discussed that one in Build failed with latest PIO

Find another chardet package and copy the entire folder here:

.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages/

You may find one here:

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages

It is not a standard python library, so you will have to obtain it from pypi.

Thanks @maxgerhardt. Does it justify filing a bug? If so, where?

@wmarchewka. I followed your advice and it seems to work. Thanks. The directory names was slightly different. I did find a clean chardet under .platformio but it was under pip/_vendor/chardet so I copied it and it to site-packages and it worked.

$ pwd                  
/Users/user/.platformio/penv/.espidf-5.0.0/lib/python3.9/site-packages
$ cp -r pip/_vendor/chardet .
1 Like

Having to copy site-packages by hand is definitely weird and should not be done by the user. Is this issue already known in Issues · platformio/platform-espressif32 · GitHub?

I think it’s the same as Project Initialization fails during Dependency Check (ESP32 Dev Module) · Issue #1045 · platformio/platform-espressif32 · GitHub so added a note there. Thanks.