Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No "Serial" Module #13

Closed
samjulien opened this issue Oct 8, 2016 · 46 comments
Closed

No "Serial" Module #13

samjulien opened this issue Oct 8, 2016 · 46 comments

Comments

@samjulien
Copy link

samjulien commented Oct 8, 2016

Hi there. Windows 8.1 here. Followed the instructions on getting set up and receiving the following when trying to upload a blinking light sketch:

Traceback (most recent call last):

  File "C:\Program Files (x86)\Arduino\hardware\espressif\esp32/tools/esptool.py", line 25, in <module>

    import serial

ImportError: No module named serial

exit status 1
Error compiling for board ESP32 Dev Module.

Any ideas?

P.S. Thanks for working on this port!

@MrAPierce
Copy link

Hi I had the same issue, you're missing pyserial. You can install pyserial via pip. Open CMD as Administrator and type: pip install pyserial

I believe that pip is installed by default when installing python, Pip should go and get pyserial and install it in the correct location. Restart Arduino IDE and Build, worked for me.

@samjulien
Copy link
Author

Ah, excellent, thanks. Now it compiles and gives me:

esptool.py v2.0-dev
Connecting...

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet ('f')

So that's something.

@MrAPierce
Copy link

MrAPierce commented Oct 9, 2016

That error seems related to uploading, double check that you are holding down boot button then pressing the reset button and then releasing both, then click upload (arrow button).

Does it compile by clicking the tick (verify) button?

@samjulien
Copy link
Author

Yes, it compiles with the verify button, and yes, I'm doing the boot-and-reset press and upload. No dice. If I open the serial monitor at 115200 I do see some boot text and info about the wifi starting, so the device is alive. I've got flash frequency at 40MHz and flash speed at 115200, are those right? And does the programmer setting matter? I've got AVRISP mkII selected.

@MrAPierce
Copy link

These are the setting that work for me:

esp32

@samjulien
Copy link
Author

Sorry for the delayed response - thanks for the screenshot. Still getting the same error for some reason. I'll keep tinkering.

@MrAPierce
Copy link

Hi @samjulien, did you have any luck getting this to work?

@sorscode
Copy link
Contributor

Hi @samjulien, Did you by chance install the Silabs driver? I was able to get my Dev board working, once I go the driver install on Mac. I just finished testing PubSubClient on the ESP32, and it works good.

@samjulien
Copy link
Author

@MrAPierce - not yet, still not sure what the problem is. I'm just uploading super simple LED blink code with an LED in pin 12 and a resistor to ground.

@sorscode - are these same drivers by Silabs used for the ESP8266? Googling "silabs esp32" took me to the same page of "CP210x USB to UART Bridge VCP Drivers," which I do have installed from working with the 8266.

Once I get this working I'm happy to submit a PR to the readme with anything pertinent. Definitely not just trying to be a pain, hoping to help out the larger community by being a guinea pig. :)

@sorscode
Copy link
Contributor

@samjulien That would be the one. Which port do you have selected when uploading? I'm going to build a quick Windows 8.1 VM and test.

@samjulien
Copy link
Author

samjulien commented Oct 11, 2016

Okay, cool, thanks. A buddy of mine pointed out that it's been several months since I installed those drivers for the ESP8266 and perhaps an update to them is in order, so I'll also give that a go and report back.

@samjulien
Copy link
Author

Hmm, updated the drivers, took away the LED, did the boot mode dance, changed sketch to just empty setup and void loops - still no dice. Same invalid head of packet error. Settings are as you have it above. Weird.

@AnalogLamb
Copy link

Hi You need to install python2.7 and pyserial,

Please see here: https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/installing-python-and-pyserial

@tamberg
Copy link

tamberg commented Nov 7, 2016

+1 for AnalogLamb, see https://github.com/pyserial/pyserial, or just type pip install pyserial
then restart the Arduino IDE. Fixed it for me.

@samjulien
Copy link
Author

Yeah, above I had already installed pyserial and was able to compile but got a different error. That was on Windows 8.1. I just got a new laptop with Windows 10 on it and will give this another shot soon.

@yashchitalia
Copy link

yashchitalia commented Nov 13, 2016

I too am seeing the serial error "ImportError: No module named serial" in spite of having both python and pyserial. When I opened up a python console on my Terminal and imported serial, that worked fine. Any suggestions?
My guess, is that the Arduino compiler isn't running the right version of Python, it may be using the default version that comes inbuilt with the Mac, but I'm not sure how I could test this theory.

@me-no-dev
Copy link
Member

Arduino compile runs the version of python that you have in the path :) so basically starting a shell without running .bash_profile and executing python. Where is your python installed? Why not use the default one (I use it daily and it's totally fine)?

@yashchitalia
Copy link

yashchitalia commented Nov 16, 2016

No that was just a theory. Turns out, I am running the inbuilt version of python, but the Arduino compiler still returns an error importing "serial". Importing serial in the terminal works fine. In fact, I printed the command that had failed in the compiler (using the verbose output functionality), and ran it in the terminal, and that executed fine.
So I'm not sure what's going on there.

@me-no-dev
Copy link
Member

your PATH variable is different if you run in terminal than what programs trying to execute command see. Usually that is limited to /usr/bin:/usr/sbin:usb/local/bin:/usr/local/sbin
run which python in terminal and see where python is. It might be different than python that might be in one of the locations by default

@yashchitalia
Copy link

So which python returns /usr/local/bin, and that's why I think its running the inbuilt version of python.

@me-no-dev
Copy link
Member

ok here is an idea :)
prepend which "{compiler.python.cmd}" && to this command and run build. it should print the path it sees right before building the bin

@me-no-dev
Copy link
Member

recipe.objcopy.hex.pattern=which "{compiler.python.cmd}" && "{compiler.python.cmd}" "{runtime.platform.path}/tools/esptool.py" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf"

@yashchitalia
Copy link

So that worked! Thanks a lot! Adding the text to platform.txt revealed that the path it was trying to use was at /usr/bin/. However, changing that path in platform.txt seems to throw a genericexit status 1 Error compiling for board ESP32 Dev Module. error. Any suggestions?

@me-no-dev
Copy link
Member

do not change the path :)
open terminal and do

sudo mv /usr/bin/python /usr/bin/python_other
sudo ln -s /usr/local/bin/python /usr/bin/python

that will link the correct python to /usr/bin and save the day :)

@yashchitalia
Copy link

yashchitalia commented Nov 16, 2016

So both those commands are forbidden. But I get the general idea. I'll try some other things out (like creating an alias, etc.), and see if that works.
Thanks a lot!

@evanmj
Copy link

evanmj commented Nov 29, 2016

I had this same issue on windows with the sparkfun board... I installed pyserial, then got the next issue. Then I went back to holding the reset button while it programmed, and it worked. Thanks guys!

@dgdosen
Copy link

dgdosen commented Nov 30, 2016

Hi all;

I'm working on a mac with homebrew installed python.

Arduino seems to be ignoring my path - as I choose to use the homebrew python over the system python.

Nevertheless, if I brew unlink python - leaving only the system python, I can:

  • run the system python
  • see that pyserial is not installed
  • install pip (using sudo)
  • install pyserial (using sudo)
  • run the python get.py command
  • compile the sketch.

I don't have my esp32 hooked up right now, but will test it later.

@dgdosen
Copy link

dgdosen commented Nov 30, 2016

FYI - the above solution works (for homebrewed python macs) I was able to upload sketches and get them working on my esp32 (ESP32 Thing from Sparkfun)

Ideally, the IDE would have recognize my path settings so one can avoid the work around.

Now I want to find/use a CLI-based toolchain to just avoid the Arduino IDE.

@me-no-dev
Copy link
Member

@dgdosen if you want to use it without the IDE:

  • Download and install esp-idf
  • Create blank idf project (from one of the examples)
  • in the project folder, create a folder called components
  • git clone this repository inside components as name arduino (git clone https://github.com/espressif/arduino-esp32.git arduino)
  • make menuconfig has some Arduino options (maybe enable arduino autostart)
  • in your main.cpp, include Arduino.h and format it as any other sketch (if autostart is enabled)
  • make flash monitor will build, upload and open serial monitor

@blackketter
Copy link

I can recommend using platform.io to do ESP32 builds on the command line without an IDE. See http://platformio.org/get-started/cli

@me-no-dev
Copy link
Member

@blackketter and how is ESP32 working on platformio?

@blackketter
Copy link

Well, I haven't dug in deeply but a blink example compiled, downloaded and ran perfectly on my SparkFun ESP32 Thing.

@anziclone
Copy link

So I figured out a workaround for this problem and got the code to work on a Mac.

  1. Install PySerial using "sudo -H pip install pyserial" in you terminal.

  2. Then get the path of python that you are working on in the terminal using "which python" command. This will give you a path name like below:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Copy this path.

  1. Open up the platform.txt in the hardware/espressif/esp32 folder.
    Change the value of compiler.python.cmd=python to compiler.python.cmd=/Library/Frameworks/Python.framework/Versions/2.7/bin/python.
    Also change the value of tools.esptool.cmd=python to tools.esptool.cmd=/Library/Frameworks/Python.framework/Versions/2.7/bin/python. This worked just fine for me and code is compiling and uploaded to the esp32 successfully.

@me-no-dev
Copy link
Member

this is now all resolved because python is no longer required on Windows

@harshithuchil
Copy link

here am working with esp32 and arduino but when i connect my esp32 its not showing me the port can anyone solve this ????

@tolo69
Copy link

tolo69 commented Nov 1, 2017

@harshithuchil, did you already solve the issue?
I face similiar Problem with ESP32DevC under win10. I have installed the CP2102 VCP-Driver. But after connecting the board it is not appearing in device Manager as virtual COM-port.

@T-vK
Copy link

T-vK commented Aug 1, 2019

On Fedora you follow these instructions: https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/fedora.md

And in addition to that, you run pip install pyserial --user. (Not as root!)

@psiphi75
Copy link

For anyone who comes here from a search engine. On Ubuntu 19.04, my version of pip is for Python 3.7, you need to install pip2.

sudo apt install python-pip

Then install pyserial

pip2 install pyserial

@JulianNicholls
Copy link

Thank you @psiphi75. That was exactly the solution on Ubuntu 19.10 as well.

@lviss
Copy link

lviss commented Jul 6, 2020

Thank you @psiphi75. That was exactly the solution on Debian 10 as well.

@cyzen
Copy link

cyzen commented Jul 10, 2020

Thank you @psiphi75. That was right step to the solution on Ubuntu 20.04 as well.
After i installed pip2 for python2,7
(https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/)
i could finally do "pip2 install pyserial"
and ESP32 compiling works at Arduino-IDE 1.8.13 without an error

@lbernstone
Copy link
Contributor

python2 is past end of life. Move forward to python3 instead of backwards.
espressif/esptool#528 (comment)

@spragiot
Copy link

spragiot commented Oct 9, 2020

to solve this issue just follow these steps

  1. install and update python
    sudo apt-get install python3 python3-pip python3-setuptools

  2. set default python version
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

regards

@vipinsinghal1234
Copy link

Issue: import serial module not found :
sudo apt install python-is-python3

for library clash :
sudo pip3 uninstall serial
sudo pip3 install pyserial

worked for me because in my case this error was due to python supported by IDE

@zume2020
Copy link

on Linux systems just try this sudo apt install python-is -python3

@fire17
Copy link

fire17 commented Aug 21, 2021

sudo apt install python-serial python3-serial

solved it! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests