Cannot flash ESP32 chip because it is using python2

With the arduino 1.8.13 IDE, I built a sketch and while flashing it to the esp32 chip, I get the following error:
AttributeError: 'Serial' object has no attribute 'dtr'

It found out that esptool is running on python2, not python3. And I guess there is no pyserial package for python2. I tried to install pyserial for python2, but there is no pip for python2, only pip3. I wonder why esp32 needs python2. With esp8266 modules, all works fine.
Can I switch arduino to python3 and how?

This comment I found in the ESP32 issue tracker indicates the opposite:

The new version requires pyserial 3, and with 2.7 it will produce an error like
AttributeError: 'Serial' object has no attribute 'dtr'

So I think the situation is that esptool requires Python 3, but for some reason Python 2 is being used.

Which operating system are you using?

It's not the opposite, it is the same. I use Ubuntu 20.04. For esp8266, python3 is used, but for esp32, python2 is used.