Python ImportError: No module named serial

2019-08-15 16:10发布

问题:

I have installed Python 2.7.5 on Ubuntu 12.4 on a DELL LATITUDE E4300 64 bit and ran:

sudo pip install pyserial

nevertheless when running:

sudo python main.py 

I receive the following error message:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    from mySerial import *
  File "/home/oscar/ath10k/tools/sanity_test/src/mySerial.py", line 6, in <module>
    import serial
ImportError: No module named serial

I looked on other posts but none of them helped me to solve this problem. I don't know what else to do I also ran:

sudo -H pip install pyserial

and

sudo pip install pyserial --upgrade

Any help will be greatly appreciated.

Kind regards.

Oscar.

回答1:

On my ubuntu 14.4 with python 2.7 as default, I installed pyserial for python3 (which my IDE is using actually) with the help of following command:

 sudo apt-get install python3-serial


回答2:

Your script name is exactly like module name, change mySerial.py to something else.



回答3:

I solved this by installing pyserial from source code instead than doing it with pip.

I do not know why it works this way and when using pip it prints error messages.