PlatformIO Community

Force Platformio to use Python3?

I’m having trouble building a project:

Processing emontx (platform: atmelavr; framework: arduino; board: uno)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (3.1.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr 5.1.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
Converting src.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
ValueError: Invalid simple block 'c057b5f4c0':
  File "/usr/local/lib/python2.7/dist-packages/platformio/builder/main.py", line 170:
    env.SConscript("$BUILD_SCRIPT")
  File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Script/SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Script/SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "/home/glyn/.platformio/platforms/atmelavr/builder/main.py", line 162:
    target_elf = env.BuildProgram()
  File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/platformio.py", line 62:
    env.ProcessProjectDeps()
  File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/platformio.py", line 140:
    project_lib_builder = env.ConfigureProjectLibBuilder()
  File "/home/glyn/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
    return self.method(*nargs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/piolib.py", line 1062:
    project.install_dependencies()
  File "/usr/local/lib/python2.7/dist-packages/platformio/builder/tools/piolib.py", line 886:
    if lm.get_package(spec):
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/manager/base.py", line 234:
    spec = self.ensure_spec(spec)
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/manager/base.py", line 102:
    return spec if isinstance(spec, PackageSpec) else PackageSpec(spec)
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/meta.py", line 119:
    self._parse(raw)
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/meta.py", line 222:
    raw = parser(raw)
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/meta.py", line 245:
    self.requirements = tokens[1].strip()
  File "/usr/local/lib/python2.7/dist-packages/platformio/package/meta.py", line 162:
    else semantic_version.SimpleSpec(str(value))
  File "/usr/local/lib/python2.7/dist-packages/semantic_version/base.py", line 618:
    self.clause = self._parse_to_clause(expression)
  File "/usr/local/lib/python2.7/dist-packages/semantic_version/base.py", line 1014:
    return cls.Parser.parse(expression)
  File "/usr/local/lib/python2.7/dist-packages/semantic_version/base.py", line 1034:
    raise ValueError("Invalid simple block %r" % block)

I think the issue is due to Platformio still using python 2

--------------------------  ----------------------------------------------
PlatformIO Core Executable  /usr/local/bin/platformio
File System Encoding        UTF-8
Locale Encoding             UTF-8
PlatformIO Core             5.0.4
System Type                 linux_x86_64
PlatformIO Core Directory   /home/glyn/.platformio
Python Executable           /usr/bin/python
Platform                    Linux-4.15.0-128-generic-x86_64-with-glibc2.15
Tools & Toolchains          5
Global Libraries            0
Development Platforms       1
Python                      2.7.17-final.0
--------------------------  ----------------------------------------------

I have python3 installed:

python3 --version
Python 3.6.9

I have followed the instructions: https://docs.platformio.org/en/latest/core/migration.html#drop-support-for-python-2-and-3-5

to remove the folder USER_HOME_DIR/.platformio/penv the reinstall pio using the install script, this didn’t seem to make any differance pio is still using python 2.7.17.

How can I force pio to use python3?

The error is independent of your used python version. The lib_deps declaration of your project is invalid (or of old style with @commithash, which doesn’t work in PIO 5).

Can you show the platformio.ini of your project?

It seems you’ve installed PlatformIO using the CLI / pip. I’d suggest you pip uninstall platformio and then pip3 install platformio – but only as a last step.

Ah, you’re correct I have a @commithash in my lib_deps, I’ve just changed to https://github.com/xxx.git#commithash and the project is now compiling again.

Do you think I should try to change pio to use python3 or will 2.7.17 be ok for the moment?

Well technically it states that the minimum version for PlatformIO Core 5.x is Python 3.6 so I think it’s better to upgrade now than before :smiley:. Shouldn’t break anything (except if using extra_scripts in projects that er specific to Python2… unlikely though)

1 Like