PlatformIO serial monitor not working

The program was build and upload, but the monitor is not working.

The terminal process "C:\Users\bannari\.platformio\penv\Scripts\platformio.exe 'device', 'monitor', '--environment', 'esp32dev'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

> Executing task in folder esp32_testWS: C:\Users\bannari\.platformio\penv\Scripts\platformio.exe device monitor --environment esp32dev <

Error: Traceback (most recent call last):
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\__main__.py", line
115, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\commands\__init__.py", line 44, in invoke
    return super(PlatformioCLI, self).invoke(ctx)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 1259, in
invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 1259, in
invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 1066, in
invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\commands\device\command.py", line 196, in device_monitor
    device_helpers.register_platform_filters(platform, options=kwargs)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\commands\device\helpers.py", line 106, in register_platform_filters
    load_monitor_filter(path, options)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\commands\device\helpers.py", line 82, in load_monitor_filter
    module = load_python_module("platformio.commands.device.filters.%s" % name, path)
  File "c:\users\bannari\.platformio\penv\lib\site-packages\platformio\compat.py", line 64, in load_python_module
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\bannari\.platformio\platforms\espressif32\monitor\filter_exception_decoder.py", line 20, in <module>
    from platformio.compat import path_to_unicode, WINDOWS, PY2
ImportError: cannot import name 'path_to_unicode' from 'platformio.compat' (c:\users\bannari\.platformio\penv\lib\site-packages\platformio\compat.py)

============================================================

An unexpected error occurred. Further steps:

* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues

============================================================

The terminal process "C:\Users\bannari\.platformio\penv\Scripts\platformio.exe 'device', 'monitor', '--environment', 'esp32dev'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

First try to update everything and see if the error still occurs.

Open a CLI and execute

pio upgrade --dev
pio platform update espressif32

Then restart VSCode and retry.

1 Like

@maxgerhardt thank you so much, it’s working now… :slight_smile:

I had the same issue today and upgrading pio and the espressif32 platform did not help. The problem appears to be caused by a check for Python2 in ~/.platformio/platforms/espressif32/monitor/filter_exception_decoder.py. Because I am not intending to use Python2 I have commented out the import and the two references to PY2 and everything works as before. Is this a bug, or is there something else I need to upgrade?

How did you install PlatformIO? Via VSCode or pip(2) install platformio? This should not be an issue anymore

Via VSCode as far as I remember - previously it had been fine for ages…

Please report exact instructions on how to reproduce the bug to Issues · platformio/platform-espressif32 · GitHub, the devs should handle it. It seems very weird that if you’ve installed PlatformIO via VSCode (which brings its own Python3 interpreter with it) that Python2 checks are firing.

What is the Python version when you use the CLI and execute pio system info?

I don’t think the checks are firing - it’s just the import from compat.py that seems to be missing and so causes an ImportError.

Here is the output from pio system info:

--------------------------  ------------------------------------------------
PlatformIO Core             5.3.0b5
Python                      3.7.4-final.0
System Type                 darwin_x86_64
Platform                    Darwin-21.3.0
File System Encoding        utf-8
Locale Encoding             UTF-8
PlatformIO Core Directory   ~/.platformio
PlatformIO Core Executable  ~/opt/anaconda3/bin/platformio
Python Executable           ~/opt/anaconda3/bin/python3.7
Global Libraries            0
Development Platforms       1
Tools & Toolchains          6
--------------------------  ------------------------------------------------

My system even fails on build, upload, and monitor. and here is my system info
P.S. I think pio core v-5.2.5 above is problematic

--------------------------  ------------------------------------------
PlatformIO Core             5.3.0b5
Python                      3.9.12-final.0
System Type                 windows_amd64
Platform                    Windows-10
File System Encoding        utf-8
Locale Encoding             cp949
PlatformIO Core Directory   C:\.platformio
PlatformIO Core Executable  C:\.platformio\penv\Scripts\platformio.exe
Python Executable           C:\.platformio\penv\Scripts\python.exe    
Global Libraries            0
Development Platforms       1
Tools & Toolchains          13
--------------------------  ------------------------------------------

I also have commented on github issue post as well in case of anyone interested about my build failure error message

github issue here