ModuleNotFoundError: No module named 'serial' - import serial

Hi,

Anyone get this error while connection to serial port in python ? I have already installed “pip install pyserial” but I get an error. The error is “ModuleNotFoundError: No module named ‘serial’”

# Serial port config
import serial
ser = serial.Serial( "COM8" , 9600 )

It sounds like a mismatch between the version of Python that installed
pyserial and the version you are trying to run.

Start by putting this in a script and running it:

import sys
print(sys.version)
print(sys.path)

and copy and paste the output. Then run this:

pip --version

and again copy and paste the output.

I get this “pip 21.1.3” when I run “pip --version”

This is the output when I run the script in .py file

“3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
[‘E:\Python_Projects\Serial’, ‘C:\Python-3.8.1\python38.zip’, ‘C:\Python-3.8.1\DLLs’, ‘C:\Python-3.8.1\lib’, ‘C:\Python-3.8.1’, ‘C:\Python-3.8.1\lib\site-packages’]”

Please copy and paste the full output that I asked for.

I’m not asking for these things to waste your time, I’m trying to help
you.

If I run “pip --version” in .py file then it says in the shell that “NameError: name ‘pip’ is not defined” but if I run “pip --version”n CMD then I get “pip 21.1.3” in CMD.

Okay that’s helpful. That tells me you are using Python 3.8, and it
shows the directories where Python is looking for libraries.

How did you install Python?

Please run this:

pip --version

not in a .py file just run it at the command prompt, on Windows
the command prompt will probably be “%” maybe “$”. You should get
output like this:

% pip --version
pip 21.0.1 from /home/steve/.local/lib/python3.9/site-packages/pip (python 3.9)

except the pathname will be different.

Can you also use the Windows Find command to search for:

serial\__init__.py

That has two underscores at the start and end of “init”:

underscore underscore init underscore underscore dot py

Thank you.