Arduino 1.8.16 on macOS Mojave fails compiling ESP32 sketches, even the simplest integrated examples. # [Error 'exec: "python": executable file not found in $PATH Error compiling for board ](https://arduino.stackexchange.com/questions/72994/error-exec-python-executable-file-not-found-in-path-error-compiling-for-bo)...
The problem exists for a very long time now and has not be solved, whereas a simple workaround fixes it:
Starting Arduino app from the terminal open /Applications/Arduino.app
solves the problem:
First of all, it is important to understand the overall situation: each Arduino boards platform provides templates from which Arduino IDE generates the commands that are used to compile and upload sketches for the boards of that platform. These commands may use any arbitrary tools. The Arduino Boards Manager will automatically install any tools specified as dependencies by the platform developer along with the installation or update of the platform. Traditionally, the platform developers have configured their platforms so that all tool dependencies are installed, providing the user with a complete environment for working with that board out of the box.
Although that is a user friendly approach, there is nothing in the Arduino boards platform framework that mandates that the platform be configured to install all its tool dependencies. The ESP32 developers took a different approach by putting the responsibility for providing the platform's Python dependency on the user when installed on a Linux or macOS system (they do provide the Python tool for Windows users). This means that, if for some reason the users system is not already set up to make Python accessible to the platform, then compilations or uploads will fail until the user has configured their system as the platform requires. So it is important to understand that encountering this error is not the result of a defect in Arduino IDE, and the problem could never be solved by a change to the IDE.
Now, as to your problem specifically. It could be solved by configuring your environment so that the python commands generated by the platform can run. Or it could be solved by modifying the platform to use python3 in those commands (assuming your environment already provides python3, which is likely).
However, there may be a better solution. That solution is to simply update the ESP32 boards platform. The ESP32 boards platform developers updated it to use python3 1.5 years ago:
That was released in version 2.0.3 of the platform. So the error you got indicates you are using a significantly outdated version of the platform. If you have a specific reason for using the outdated version, then that is fine and you can use one of the workarounds to fix the error. But if you don't have a reason for using the outdated platform version then I recommend you to simply update to the latest version. That will give you all the fixes and enhancements made to the platform over the last >1.5 years of development in addition to fixing the error you are experiencing now.
The most common reason users end up with an outdated version of the ESP32 platform is that Espressif changed the URL you use in your "Additional Boards Manager URLs" preference to get updates of the platform. They stopped maintaining the old URL so you don't get any updates past 1.0.6 when using that URL. In this case, it will be necessary to update your preferences in order to get the update. I'll provide instructions:
Copy the URL shown under the "Stable release link" section of that page.
Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
The "Preferences" dialog will open.
If there is already a URL for the ESP32 boards platform in the "Additional Boards Manager URLs" field of the "Preferences" dialog, delete it.
Add the URL you copied from the ESP32 boards platform installation instructions to the "Additional Boards Manager URLs" field. ⓘ If there are other URLs in the field, separate them with commas (,).
Click the "OK" button on the "Preferences" dialog.
You will now see a "Downloading index: ..." notification at the bottom right corner of the IDE window. Wait for that notification to close.
Select Tools > Board > Boards Manager from the Arduino IDE menus to open the "Boards Manager" view in the left side panel.
Scroll down through the list of boards platforms until you see the "esp32 by Espressif Systems" entry.
Click the "INSTALL" button at the bottom of the entry.
Partially solved: It needed a reboot and the Arduino IDE
MUST be called from the terminal using open /Applications/Arduino.app
If you call the Arduino IDE from the Application folder you still get the error !
Hi @RIN67630. There are multiple ways of configuring the PATH environment variable on macOS:
The /etc/paths file and files under the /etc/paths.d/ folder.
The configuration files of the shell you are using (e.g., ~/.zshenv, ~/.zprofile, ~/.zshrc if you are using Zsh or ~/.bashrc, ~/.bash_profile if you are using Bash).
The PATH variable will generally be set by a combination of the contents of these configuration files so there isn't one single source of paths. The shell configuration files may only have an effect if you are using that shell, and even in the way you are using the shell (some are applied on login and others only when starting an interactive terminal session).
So the reason why it works when you start Arduino IDE from a terminal, but not when starting it directly might be because the path is set in a shell configuration file that is only active when you are using the terminal.