6

I googled and couldn't find a solution to my nice problem: I have Ubuntu and I want to program a ESP32 ............... I tried a lot of pip commands ... but it didnt work. You have any idea how to install the correct packages? Maybe you can tell me what to do. I am really lost. I tried it last year and also failed.. Now I want to try it another time :)

   /.arduino15/packages/esp32/tools/esptool_py/3.0.0/esptool.py", line 38, in <module>
        import serial
    ImportError: No module named serial
0

4 Answers 4

9

Open terminal and enter this command python -m pip install pyserial it will download pyserial for you and you will not receive the above error. The above error is because you don't have pyserial installed on the system.

The related documentation for pyserial could be found here

3
  • 1
    python -m pip install pyserial /usr/bin/python: No module named pip
    – jento
    Commented Nov 26, 2021 at 4:25
  • 1
    @jento you will first need to install pip I considered you have pip installed to install pip use the following command sudo apt install python3-pip for python3 or you can use sudo apt install python-pip for python 2
    – Maaz Sk
    Commented Dec 12, 2021 at 5:33
  • How about doing this but in a virtualenv, so not installing packages system wise?
    – Gauthier
    Commented Aug 8, 2023 at 10:50
3

I had the same issue compiling the CameraWebServer example. I'm using Ubuntu 20.04. The problem occurs during the linking stage when the script invokes python. On my system this runs the system python which is python 2.7.18. I don't think the serial module (supplied by pyserial) is available on Ubuntu 20.04 for python 2.x.

My solution was first to abandon the Arduino IDE and use the arduino-cli to compile the example. I created a virtual python 3 environment, activated it, installed pyserial under the virtual environment and run arduino-cli to make the runtime. The python scripts appear to be compatible with python 3.

2
  • 1
    the arduino esp32 python scripts work with python 2 and you can install pyserial into python 2.
    – Juraj
    Commented Mar 29, 2022 at 13:12
  • 1
    I'm not sure it's available for 2.7.18. In any case, I did not want to install libs into the system python just to make a runtime when I can use a virtual env.
    – candor
    Commented Mar 29, 2022 at 14:31
1

Problem resolved, Thank you. I had installed pyserial. The error surprisingly was related to the incorrect processor speed (!) in the Arduino IDE. I have no idea why that would influence the serial/pyserial function.

1

Reference: https://www.how2shout.com/linux/how-to-install-python-2-7-on-ubuntu-20-04-lts/

I think Arduino IDE expects Python2 to be installed. My Version is Arduino-1.8.13 You also need Python2 modules so you need to install pip2

:~/curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py :~/sudo python2 get-pip.py :~/pip2 install pytools :~/pip2 install pyserial

Not the answer you're looking for? Browse other questions tagged or ask your own question.