Follow the steps at the [Espressif Getting Started guide](https://docs.espressif.com/projects/esp-idf/en/v4.0/get-started/index.html#step-3-set-up-the-tools).
This will guide you through using the `install.sh` (or `install.bat`) script
to download the toolchain and add it to your `PATH`. The steps are summarised
below:
After you've cloned and checked out the IDF to the correct version (see
above), run the `install.sh` script:
```bash
$ pip install pyserial 'pyparsing<2.4'
$ cd$ESPIDF
$ ./install.sh # (or install.bat on Windows)
```
It is recommended to use a Python virtual environment if your system package
manager already provides these libraries, especially as the IDF v4.x is
currently incompatible with pyparsing 2.4 and higher.
Then in the `ports/esp32` directory, source the `export.sh` script to set the
`PATH`.
Once everything is set up you should have a functioning toolchain with
prefix xtensa-esp32-elf- (or otherwise if you configured it differently)
as well as a copy of the ESP-IDF repository. You will need to update your `PATH`
environment variable to include the ESP32 toolchain. For example, you can issue
the following commands on (at least) Linux:
```bash
$ cd micropython/ports/esp32
$ source$ESPIDF/export.sh # (or path\to\esp-idf\export.bat on Windows)
$ # Run make etc, see below.
```
The `install.sh` step only needs to be done once. You will need to source
`export.sh` for every new session.
Note: If you get an error about `--no-site-packages`, then modify
`$ESPIDF/tools/idf_tools.py` and make the same change as [this