Error with 'pio run'

Hi,

I came to use VSC today and got this error:

I had it a couple of times before and usually a fresh install solved it, but not today. I get the same when using the CLI.

Can anyone give me a fix please?

Many thanks,

Andy

The stacktrace is cut-off, please post it in text fully.

Does this happen with the latest PlatformIO core too? CLIpio upgrade --dev + pio run.

Hi Max,

Here is the full trace:

Platform Manager: Installing espressif32
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Platform Manager: espressif32@5.2.0 has been installed!
Tool Manager: Installing espressif/toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Tool Manager: toolchain-xtensa-esp32@8.4.0+2021r2-patch3 has been installed!
Tool Manager: Installing platformio/framework-arduinoespressif32 @ ~3.20005.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Tool Manager: framework-arduinoespressif32@3.20005.220925 has been installed!
Tool Manager: Installing platformio/tool-esptoolpy @ ~1.40201.0
Downloading  [####################################]  100%
Unpacking  [####################################]  100%
Tool Manager: tool-esptoolpy@1.40201.0 has been installed!
Removing unused dependencies...
Error: Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/cli.py", line 71, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/cli.py", line 144, in cli
    process_env(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/cli.py", line 201, in process_env
    result = {"env": name, "duration": time(), "succeeded": ep.process()}
                                                            ^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/processor.py", line 83, in process
    install_project_env_dependencies(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 132, in install_project_env_dependencies
    _install_project_env_libraries(project_env, options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 204, in _install_project_env_libraries
    _uninstall_project_unused_libdeps(project_env, options)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 280, in _uninstall_project_unused_libdeps
    lm.uninstall(spec)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/_uninstall.py", line 29, in uninstall
    return self._uninstall(spec, skip_dependencies)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/_uninstall.py", line 34, in _uninstall
    pkg = self.get_package(spec)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/base.py", line 263, in get_package
    spec = self.ensure_spec(spec)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/base.py", line 133, in ensure_spec
    return spec if isinstance(spec, PackageSpec) else PackageSpec(spec)
                                                      ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 184, in __init__
    self._parse(self.raw)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 291, in _parse
    raw = parser(raw)
          ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 316, in _parse_requirements
    self.requirements = tokens[1].strip()
    ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 231, in requirements
    else semantic_version.SimpleSpec(str(value))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 647, in __init__
    self.clause = self._parse_to_clause(expression)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 1043, in _parse_to_clause
    return cls.Parser.parse(expression)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 1063, in parse
    raise ValueError("Invalid simple block %r" % block)
ValueError: Invalid simple block '^4.1.build_flags ='

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

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/index.html

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

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


 ✘ andy  ~/Documents/PlatformIO/Projects/Heltec_LoRaWan 
 pio upgrade
You're up-to-date!
PlatformIO 6.1.5 is currently the newest version available.

 andy  ~/Documents/PlatformIO/Projects/Heltec_LoRaWan 
 pio upgrade --dev
Please wait while upgrading PlatformIO ...
PlatformIO has been successfully upgraded to 6.1.6a4
Release notes: https://docs.platformio.org/en/latest/history.html

 andy  ~/Documents/PlatformIO/Projects/Heltec_LoRaWan 
 pio run
Please wait while upgrading PlatformIO...
PlatformIO has been successfully upgraded to 6.1.6a4!

*************************************************************************************************************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for embedded development > https://platformio.org/platformio-ide
*************************************************************************************************************************************************************************

Processing heltec_wifi_lora_32_V2 (platform: espressif32; board: heltec_wifi_lora_32_V2; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Removing unused dependencies...
Error: Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
    ^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/cli.py", line 71, in invoke
    return super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/cli.py", line 144, in cli
    process_env(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/cli.py", line 201, in process_env
    result = {"env": name, "duration": time(), "succeeded": ep.process()}
                                                            ^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/run/processor.py", line 83, in process
    install_project_env_dependencies(
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 132, in install_project_env_dependencies
    _install_project_env_libraries(project_env, options),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 204, in _install_project_env_libraries
    _uninstall_project_unused_libdeps(project_env, options)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/commands/install.py", line 280, in _uninstall_project_unused_libdeps
    lm.uninstall(spec)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/_uninstall.py", line 29, in uninstall
    return self._uninstall(spec, skip_dependencies)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/_uninstall.py", line 34, in _uninstall
    pkg = self.get_package(spec)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/base.py", line 263, in get_package
    spec = self.ensure_spec(spec)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/manager/base.py", line 133, in ensure_spec
    return spec if isinstance(spec, PackageSpec) else PackageSpec(spec)
                                                      ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 184, in __init__
    self._parse(self.raw)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 291, in _parse
    raw = parser(raw)
          ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 316, in _parse_requirements
    self.requirements = tokens[1].strip()
    ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/package/meta.py", line 231, in requirements
    else semantic_version.SimpleSpec(str(value))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 647, in __init__
    self.clause = self._parse_to_clause(expression)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 1043, in _parse_to_clause
    return cls.Parser.parse(expression)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/semantic_version/base.py", line 1063, in parse
    raise ValueError("Invalid simple block %r" % block)
ValueError: Invalid simple block '^4.1.build_flags ='

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

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/index.html

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

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

The problem occurs in 6.1.5, 6.1.6a4 VSC and CLI. I also keep getting multiple core messages, but don’t really understand or how to avoid it.

I’ve updated Python (to 3.11.1), installed pyenv, deleted .platformio multiple times and reinstalled platformio in VSC several times.

No luck with your suggestion:

 pio upgrade --dev
Please wait while upgrading PlatformIO …
PlatformIO has been successfully upgraded to 6.1.6a4
Release notes: Redirecting...

andy  ~/Documents/PlatformIO/Projects/Heltec_LoRaWan 
 pio run
Processing heltec_wifi_lora_32_V2 (platform: espressif32; board: heltec_wifi_lora_32_V2; framework: arduino)

Removing unused dependencies…
Error: Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/platformio/main.py”, line 102, in main
cli() # pylint: disable=no-value-for-parameter
^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py”, line 1130, in call
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py”, line 1055, in main
rv = self.invoke(ctx)

  1. It looks like you’ve globally installed PlatformIO, references to /Library/Frameworks/Python.framework should normally not be in theh stacktrace
  2. What’s the platformio.ini? Where does ^4.1.build_flags = come from?

Here’s my machine spec:

The last attempt I made was using the installation script. I also had the error with a local installation.

platformio.ini:

[env:heltec_wifi_lora_32_V2]
platform = espressif32
board = heltec_wifi_lora_32_V2
framework = arduino
monitor_speed = 115200
lib_deps = mcci-catena/MCCI LoRaWAN LMIC library@^4.1.1

Thanks for the quick answer btw!

I have no problems with that platformio.ini.

The error suggests that the last part has some .build_flags = ... stuff after it. The file is possibly corrupted?

Try and delete the platformio.ini and create it anew with that exact content.

I tested it to compile with source code

#include <Arduino.h>
#include <lmic.h>
#include <SPI.h>
void setup(){}
void loop(){}

Resulting in

Linking .pio\build\heltec_wifi_lora_32_V2\firmware.elf
Retrieving maximum program size .pio\build\heltec_wifi_lora_32_V2\firmware.elf
Checking size .pio\build\heltec_wifi_lora_32_V2\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.9% (used 16144 bytes from 327680 bytes)
Flash: [=         ]   6.4% (used 213009 bytes from 3342336 bytes)
Building .pio\build\heltec_wifi_lora_32_V2\firmware.bin
esptool.py v4.2.1
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
============================================= [SUCCESS] Took 10.05 seconds =============================================

Back in VSC now:

Same result again with:

#include <Arduino.h>
#include <SPI.h>
void setup(){}
void loop(){}

At the start of the day, my Python was 3.9.

The project is a reference version that I fall back on when I want a basic LoRaWan connection. As such it hasn’t changed. The problem seemed to come from nowhere this morning .

Also, I didn’t change anything or carry out any upgrades prior to switching to the project. I had been working on a another project before switching back to this one.

Just before I turn my laptop off, the problem seems to be limited to the one project. I’m going to have to scrap it and start again, but at least everything else sems to work.

Thanks again for your time Max:-).

Hi Max,

Just to finish the story and for anyone else with the problem, I created a new folder this morning and copied the platformio.ini to it. Using the minimal program above, I still got the error message. I removed the libdeps line with the reference to the lmic library and was able to compile a minimal installation (without the reference to lmic, of course). Then I reinserted the library line and copied the original program into main.cpp and everything worked! It seems very weird. Deleting the platform.ini didn’t work yesterday, in the original folder.

I learned a lot from this episaode and now know how to deal with multiple Python installations on the Mac and best of all, I’ve been able to move away from VSC and use Vim as my editor of choice. I wasn’t aware that this was possible until yesterday!