pyserial: No module named tools
Question:
I have installed the latest pySerial on my Ubuntu box with python 2.7.2, and it works fine for most things, but whenever I try to import the ‘tools’ package, it says that it can’t find ‘tools’. The documentation for pySerial explicitly references this ‘tools’ package.
>>> from serial import tools
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
import serial.tools
ImportError: No module named tools
and when I:
>>> serial.VERSION
'2.5'
which is the latest version according to Source Forge
So why can’t I get to the ‘tools’ package of pySerial?
Answers:
You have to call the functions of module this way:
from serials import tools
For example: If I want to call sqrt
function from math
module, I would do:
from math import sqrt
import math.sqrt **is wrong.**
It looks like the ubuntu package does not quite match up with upstream. compare the official pySerial package on their SVN:
http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/serial/
to the ubuntu package in launchpad:
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/raring/pyserial/raring/files/head:/serial/
Tools is missing there, too. It does look like they keep the miniterm.py
script, and install it… somewhere; I’m not versed enough in deb packaging to understand where, though.
Use pip
to install pyserial
. First install pip:
sudo apt-get install python-pip
After that install pyserial
:
sudo pip install pyserial
I got here because I had the same problem.
The strange thing was that
import serial
worked, but
from serial.tools import list_ports
didn’t.
Turns out stupid me named the script “serial.py”. After renaming it everything worked.
yes,use python-pip install ,,,then ,,,upgrade,,,the version of serial will be 2.7 …it workes
Just in case that doing “pip install –upgrade” doesn’t work(as happened to me), in Linux you can check if you have a serial package in /usr/lib/python2.7/dist-packages
, the new serial packaged the one that pip install goes to /usr/**local**/lib/python2.7/dist-packages/serial
, for some reason the one in usr/lib/python2.7/
has precedence and the module tools doesn’t exist in that version of pyserial. Changing names or deleting the directory solve the problem.
The pyserial-2.4-py2.7.egg in the site-packages folder was getting imported instead of from serial in the site-packages folder. Once I renamed this file so that it no longer imported from this it worked fine. You can easily debug this by doing
import serial
serial._ _path_ _
to see where serial is getting imported from.
From the pyserial webpage: https://pyserial.readthedocs.io/en/latest/pyserial.html
They recommend that you use the command:
python -m pip install pyserial
That worked for me. I don’t know enough about pip to undersand the difference from just a regular pip install pyserial, but it worked for me (after much frustration).
In my case, I installed serial
but not pyserial
after getting the following error.
ImportError: No module named 'serial'
Then import serial
was ok, but from serial import tools
can’t work.
Just sudo pip uninstall serial
and sudo pip install pyserial
Hope to help people like me.
the difference between pip and python -m pip can be the version. for example, it may be that you call pip from python2, but when you type python -m pip then you get python3 and so on…
You have to uninstall serial
and pyserial
then reinstall pyserial
:
pip uninstall serial
pip uninstall pyserial
pip install pyserial
Because the both libs contain a file named serial.py
, you get a name conflict.
I have installed the latest pySerial on my Ubuntu box with python 2.7.2, and it works fine for most things, but whenever I try to import the ‘tools’ package, it says that it can’t find ‘tools’. The documentation for pySerial explicitly references this ‘tools’ package.
>>> from serial import tools
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
import serial.tools
ImportError: No module named tools
and when I:
>>> serial.VERSION
'2.5'
which is the latest version according to Source Forge
So why can’t I get to the ‘tools’ package of pySerial?
You have to call the functions of module this way:
from serials import tools
For example: If I want to call sqrt
function from math
module, I would do:
from math import sqrt
import math.sqrt **is wrong.**
It looks like the ubuntu package does not quite match up with upstream. compare the official pySerial package on their SVN:
http://pyserial.svn.sourceforge.net/viewvc/pyserial/trunk/pyserial/serial/
to the ubuntu package in launchpad:
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/raring/pyserial/raring/files/head:/serial/
Tools is missing there, too. It does look like they keep the miniterm.py
script, and install it… somewhere; I’m not versed enough in deb packaging to understand where, though.
Use pip
to install pyserial
. First install pip:
sudo apt-get install python-pip
After that install pyserial
:
sudo pip install pyserial
I got here because I had the same problem.
The strange thing was that
import serial
worked, but
from serial.tools import list_ports
didn’t.
Turns out stupid me named the script “serial.py”. After renaming it everything worked.
yes,use python-pip install ,,,then ,,,upgrade,,,the version of serial will be 2.7 …it workes
Just in case that doing “pip install –upgrade” doesn’t work(as happened to me), in Linux you can check if you have a serial package in /usr/lib/python2.7/dist-packages
, the new serial packaged the one that pip install goes to /usr/**local**/lib/python2.7/dist-packages/serial
, for some reason the one in usr/lib/python2.7/
has precedence and the module tools doesn’t exist in that version of pyserial. Changing names or deleting the directory solve the problem.
The pyserial-2.4-py2.7.egg in the site-packages folder was getting imported instead of from serial in the site-packages folder. Once I renamed this file so that it no longer imported from this it worked fine. You can easily debug this by doing
import serial
serial._ _path_ _
to see where serial is getting imported from.
From the pyserial webpage: https://pyserial.readthedocs.io/en/latest/pyserial.html
They recommend that you use the command:
python -m pip install pyserial
That worked for me. I don’t know enough about pip to undersand the difference from just a regular pip install pyserial, but it worked for me (after much frustration).
In my case, I installed serial
but not pyserial
after getting the following error.
ImportError: No module named 'serial'
Then import serial
was ok, but from serial import tools
can’t work.
Just sudo pip uninstall serial
and sudo pip install pyserial
Hope to help people like me.
the difference between pip and python -m pip can be the version. for example, it may be that you call pip from python2, but when you type python -m pip then you get python3 and so on…
You have to uninstall serial
and pyserial
then reinstall pyserial
:
pip uninstall serial
pip uninstall pyserial
pip install pyserial
Because the both libs contain a file named serial.py
, you get a name conflict.