Skip to content

Deprecation of Python 2. Solution #4717

Closed
@Martin-Laclaustra

Description

@Martin-Laclaustra

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.4
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 460800
Computer OS: Linux Mint 20.1 Ulyssa (base: Ubuntu 20.04 focal)

Description:

Due to deprecation of Python 2 some Linux distributions have decided to remove the generic "python" executable from the path, forcing all code to explicitly declare which version of Python they require (A wise solution in my opinion, as it serves as "canary" for undefined code and prevents obscure errors, resolving the longstanding ambiguity, and still allows the use of older python 2 code). This change has been annoying when one's mind is in other tasks, but one must adapt to new times and deprecation was announced years ago.
Because of this, installing the ESP32 boards in Arduino IDE results in a compilation error and uploading errors. The first error that appears is:

exec: "python": executable file not found in $PATH
Error compiling for board ESP32 Dev Module.

This issue has been raised before, and dismissed in this project:
#3696
#4017

...while it has been addressed early in the independent project "Arduino core for ESP8266":
esp8266/Arduino#6378

Solution:

It seems reasonable to stop forcing users to modify system-wide python setting when the solution seems relatively easy (while I did not weight in possible adaptations needed in other platforms).
I can confirm that the following modification in the "1.0.4" release files fixes the problem.
Files:

esp32/hardware/esp32/1.0.4/tools/espota.py
esp32/hardware/esp32/1.0.4/tools/esptool.py
esp32/hardware/esp32/1.0.4/tools/gen_esp32part.py
esp32/tools/esptool_py/2.6.1/esptool.py

only need to change the first line to: #!/usr/bin/env python3
In file: esp32/hardware/esp32/1.0.4/platform.txt, 4 lines need to be changed, just adding a "3":

-tools.esptool_py.network_cmd=python "{runtime.platform.path}/tools/espota.py"
+tools.esptool_py.network_cmd=python3 "{runtime.platform.path}/tools/espota.py"
-tools.gen_esp32part.cmd=python "{runtime.platform.path}/tools/gen_esp32part.py"
+tools.gen_esp32part.cmd=python3 "{runtime.platform.path}/tools/gen_esp32part.py"
-recipe.objcopy.hex.pattern.linux=python "{tools.esptool_py.path}/{tools.esptool_py.cmd}" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
+recipe.objcopy.hex.pattern.linux=python3 "{tools.esptool_py.path}/{tools.esptool_py.cmd}" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"
-tools.esptool_py.upload.pattern.linux=python "{path}/{cmd}" --chip esp32 --port "{serial.port}" --baud {upload.speed}  --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size detect 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x1000 "{runtime.platform.path}/tools/sdk/bin/bootloader_{build.boot}_{build.flash_freq}.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin"
+tools.esptool_py.upload.pattern.linux=python3 "{path}/{cmd}" --chip esp32 --port "{serial.port}" --baud {upload.speed}  --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size detect 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x1000 "{runtime.platform.path}/tools/sdk/bin/bootloader_{build.boot}_{build.flash_freq}.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin"

That was enough. However, I do not know if files "sdkconfig" and "sdkconfig.h" would need a change in the lines referring to the flag CONFIG_PYTHON="python", adding the "3".

There is still one system-wide dependency to meet, requiring sudo apt install python3-serial. I believe that they solved it with a sort of "local copy of the code" in the "Arduino core for ESP8266" project but I do not know the details. May be @earlephilhower could provide some advice on how they did it.

I hope that this report is useful and that you decide to uptake the proposed changes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions