Reputation: 1513
and I got a question when I run my Python code.
I installed Python 2.7 on Windows 7, bit 64. I got an error "No module named serial" when I compiled my code:
import serial
ser = serial.Serial("COM5", 9600)
ser.write("Hello world")
x = ser.readline()
print(x)
I tried many ways to crack this problem, such as installed Canopy to setup virtual environment, make sure 'pip' is there, no Python v 3.x installed. But still cannot get it out.
Any advice would be appreciated.
Upvotes: 99
Views: 548945
Reputation: 116
I had this error on Linux when ran python with sudo, reinstalling pyserial with sudo helped me:
sudo pip3 install pyserial
Link: https://blog.finxter.com/modulenotfounderror-no-module-named-serial-in-python/
Upvotes: 0
Reputation:
Happened to me. Something was broken. All the solutions presented didn't work.
sudo pip install serial Requirement already satisfied: serial in /usr/local/lib/python3.8/dist-packages (0.0.97)
sudo pip3 install serial Requirement already satisfied: serial in /usr/local/lib/python3.8/dist-packages (0.0.97)
Same for pyserial, it was already installed.
Solution: I replaced the symbolic link /usr/bin/python to use python3 instead of python2.
Upvotes: 2
Reputation: 21
Usually what can happen as was in my case is installing a newer version manually can change the placement of the pyserial from minimal to the upgraded version.
For example, I had just installed Python 3.10 before installing Arduino IDE and that just caused a heck of problems.
I uninstalled pyserial by trying pip uninstall and then
I uninstalled python3.10,
sudo apt purge python3.10
Which after a reboot later, I installed pip install pyserial again, and that did the trick.
Upvotes: 0
Reputation: 161
sudo apt install python-serial python3-serial
Solved it, using it for esp32
Upvotes: 11
Reputation: 63
I had this same problem multiple times but finally found solution.
I had multiple Python versions installed. Like in Raspberry Pi there was Python3.5 installed and I installed also 3.9.2 without uninstalling 3.5. Then I installed pyserial with pip and tried my program. No module... But the reason was that the linux symbolic link in python3 pointed to python3.9.2 version but pip3 pointed to python3.5. So pyserial was installed in python3.5 and understandably was not found when run python3.9.2. Then I changed symbolic link in pip3 to right version and voila, everything works fine!
Upvotes: 4
Reputation: 101
First use command
pip uninstall pyserial
Then run again
pip install pyserial
The above commands will index it with system interpreter.
Upvotes: 10
Reputation: 310
pip uninstall pyserial
Upvotes: 2
Reputation: 127
You must have the pyserial library installed. You do not need the serial library.Therefore, if the serial library is pre-installed, uninstall it. Install the pyserial libray. There are many methods of installing:-
pip install pyserial
pip install <wheelname>
Link: https://github.com/pyserial/pyserial/releases
After installing Pyserial, Navigate to the location where pyserial is installed. You will see a "setup.py" file. Open Power Shell or CMD in the same directory and run command "python setup.py install
".
Now you can use all functionalities of pyserial library without any error.
Upvotes: 9
Reputation: 75
Download this file :- (https://pypi.python.org/packages/1f/3b/ee6f354bcb1e28a7cd735be98f39ecf80554948284b41e9f7965951befa6/pyserial-3.2.1.tar.gz#md5=7142a421c8b35d2dac6c47c254db023d):
cd /opt
sudo tar -xvf ~/Downloads/pyserial-3.2.1.tar.gz -C .
cd /opt/pyserial-3.2.1
sudo python setup.py install
Upvotes: 5
Reputation: 1827
Serial is not included with Python. It is a package that you'll need to install separately.
Since you have pip installed you can install serial from the command line with:
pip install pyserial
Or, you can use a Windows installer from here. It looks like you're using Python 3 so click the installer for Python 3.
Then you should be able to import serial as you tried before.
Upvotes: 150