# Cannot flash ESP32 chip because it is using python2

**URL:** <https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856>\
**Category:** IDE 1.x\
**Created:** [October 17, 2020, 3:40pm UTC](https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856 "2020-10-17T15:40:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jms3000](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jms3000](https://forum.arduino.cc/u/jms3000)\
**Post date:** [October 17, 2020, 3:40pm UTC](https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856/1 "2020-10-17T15:40:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [October 17, 2020, 7:46pm UTC](https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856/2 "2020-10-17T19:46:07Z")

</div>

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

> <https://github.com/espressif/arduino-esp32/issues/1161#issuecomment-554174588>
>
> \### Hardware:
> Board: ?ESP32 Dev Module?
> Core Installation/update date: …	?11/jul/2017?
> IDE name: ?Arduino IDE? ?Platform.io? ?IDF component?
> Flash Frequency: ?40Mhz?
> Upload Speed: ?115200?
> 
> 
> \### Description:
> For a few days I have been installing the arduino-esp32 development enviroment again and again. But failed all the time. The esp32 module could been found in the arduino. But when compile and upload , it failed... The error message is as below:
> 
> Archiving built core (caching) in: C:\\DOCUME~1\\dell\\LOCALS~1\\Temp\\arduino\_cache\_197603\\core\\core\_espressif\_esp32\_esp32\_FlashMode\_qio,FlashFreq\_80,FlashSize\_4M,UploadSpeed\_921600,DebugLevel\_none\_2b738b201fc88a468b2acb947ad43f23.a
> Traceback (most recent call last):
> 
> File "esptool.py", line 25, in \<module\>
> 
> File "c:\\python27\\Lib\\site-packages\\PyInstaller\\loader\\pyimod03\_importers.py", line 389, in load\_module
> 
> # executes the module code. This is crucial because the module
> 
> File "site-packages\\serial\\\_\_init\_\_.py", line 27, in \<module\>
> 
> File "c:\\python27\\Lib\\site-packages\\PyInstaller\\loader\\pyimod03\_importers.py", line 389, in load\_module
> 
> # executes the module code. This is crucial because the module
> 
> File "site-packages\\serial\\serialwin32.py", line 15, in \<module\>
> 
> File "c:\\python27\\Lib\\site-packages\\PyInstaller\\loader\\pyimod03\_importers.py", line 389, in load\_module
> 
> # executes the module code. This is crucial because the module
> 
> File "site-packages\\serial\\win32.py", line 182, in \<module\>
> 
> File "ctypes\\\_\_init\_\_.py", line 375, in \_\_getattr\_\_
> 
> File "ctypes\\\_\_init\_\_.py", line 380, in \_\_getitem\_\_
> 
> AttributeError: function 'CancelIoEx' not found
> 
> Failed to execute script esptool
> 
> exit status -1
> 
> My PC is windows xp sp3, python use python 2.7. I have tried the following methods:
> ----try python2.7.10 and then 2.7.12
> -----change pyserial from 2.7 to pyserial3.0.1;
> -----change arduino from version 1.8.2 to 1.8.5;
> -----change the directory from" C:\\Documents and Settings\\dell\\My Documents\\Arduino\\hardware \\espressif\\esp32" to "C:\\Program Files\\Arduino\\hardware\\espressif\\esp32"
>       
> All the time it failed. This trouble me for a few days. Anyone know how to resolve this problem, thanks very much!

> 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?

---

<div class="post-metadata">

**Author:** ![jms3000](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jms3000](https://forum.arduino.cc/u/jms3000)\
**Post date:** [October 18, 2020, 6:31pm UTC](https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856/3 "2020-10-18T18:31:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 4:27pm UTC](https://forum.arduino.cc/t/cannot-flash-esp32-chip-because-it-is-using-python2/678856/4 "2021-05-05T16:27:17Z")

</div>

Closed on May 5, 2021, 4:27pm UTC


