ModuleNotFoundError: No module named 'serial'

Hi,

I am getting below error “ModuleNotFoundError: No module named ‘serial’” when I import serial in my code. Tried multiple times to uninstall pyserial and install again but still getting same error.

Got below on terminal when I print the print(sys.version) and print(sys.path) in my script:

3.12.7 (main, Nov 22 2024, 20:28:41) [GCC UCRT 14.2.0 64 bit (AMD64)]
[‘C:\00Mahendra\mod_pwr_supply_bootloader\automation_python_script’, ‘C:\msys64\ucrt64\lib\python312.zip’, ‘C:\msys64\ucrt64\lib\python3.12’, ‘C:\msys64\ucrt64\lib\python3.12\lib-dynload’, ‘C:\msys64\ucrt64\lib\python3.12\site-packages’]
Traceback (most recent call last):
File “C:\00Mahendra\mod_pwr_supply_bootloader\automation_python_script\new_working_script.py”, line 8, in
import serial
ModuleNotFoundError: No module named ‘serial’

When I run pip --version:
PS C:\00Mahendra\mod_pwr_supply_bootloader\automation_python_script> pip --version
pip 25.1.1 from C:\Users\mrana01\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip (python 3.12)

Please help how I can fix it?

Hello,

in your command prompt, can you install the package by this command:

py -m pip install serial

In the search bar at the bottom of your terminal, type cmd … and Command Prompt should come up.

Here is a little background to help you out:

The module is called serial, but the package itself is actually called pyserial.

Hi Paul,

I already tried this but not worked for me. Still, I am getting same error.

PS C:\00Mahendra\mod_pwr_supply_bootloader\automation_python_script> py -m pip install serial
Requirement already satisfied: serial in c:\users\mrana01\appdata\local\programs\python\python312\lib\site-packages (0.0.97)
Requirement already satisfied: future>=0.17.1 in c:\users\mrana01\appdata\local\programs\python\python312\lib\site-packages (from serial) (1.0.0)
Requirement already satisfied: pyyaml>=3.13 in c:\users\mrana01\appdata\local\programs\python\python312\lib\site-packages (from serial) (6.0.2)
Requirement already satisfied: iso8601>=0.1.12 in c:\users\mrana01\appdata\local\programs\python\python312\lib\site-packages (from serial) (2.1.0)

Is it some version mismatch between python and serial module?

I tried multiple things like latest python 3.12.x, installed all required modules mentioned in init.py file of serial module but I am still getting the same error.

Can someone quickly help as I am stuck from last 2 days due this error.

As I said previously, the module is called serial, but the package is called pyserial, so that should be:

py -m pip install pyserial
1 Like

@mrab is likely correct. Check out this stack overflow post: https://stackoverflow.com/questions/64383756/has-python-package-serial-been-renamed-to-pyserial. I have used serial on py3.12 before , so I can tell you for sure in a while, but I can’t get to my laptop this instant.

I know I’m right because I have it installed. :slight_smile:

That other package (“serial”) is, I believe, concerned with serialisation. And, yes, it’s confusing.

Sometimes the package name isn’t the same as the module name, even when there’s only one module in that package.

1 Like

Confirmed. For anyone interested, here is a picture

That was already installed on my laptop:
PS C:\00Mahendra\mod_pwr_supply_bootloader\automation_python_script> py -m pip install pyserial
Requirement already satisfied: pyserial in c:\users\mrana01\appdata\local\programs\python\python312\lib\site-packages (3.5)

Do you have the serial library as well? That might be causing conflicts during import that sometimes don’t surface.

Or are you in a virtual enviornment?

No, I am not working on virtual environment.
Also checked in the site packages folder so only one serial folder it has.

I have installed only on my user login. Is it this installation need admin login to get all rights or is it fine for particular user?

It looks like the script is running in msys64 (from your sys.path output C:\msys64\ucrt64\lib\python3.12\site-packages), but your calls to pip are running in a native Python installation: pip --version pip 25.1.1 from C:\Users\mrana01\AppData\Local\Programs\Python\Python312\Lib\site-packages\pip

Ultimately, the fix is to make sure that you’re using the same Python when you call pip as when you run your automation script. That means either using python -m pip from the script’s python executable, or modifying the script to use the Python executable in your local AppData directory.

2 Likes

I’ve just done some testing.

I installed the serial package and found that it broke the pyserial package. It appears that the serial package installs a module called serial, which conflicts with the serial module of pyserial package.

Even after uninstalling the serial package, the pyserial package was still broken.

I had to uninstall the pyserial package and then re-install it.

It’s now working again.

This is also likely to be correct. The python installation can’t find the serial module unless you have explicitly installed it to the C:\msys64 dir. If you’re pip is saving to the python installed in your users dir, it wont be available in the msys2 dir.

I’ve had a similar issue with having multiple installations of packages on different virtual hard drives, and usually checking what python executable you’re using is important

Ohh, Thanks @sharktide @kapinga.

When I copied serial folder from local user folder to msys2 dir path then it worked.

Thank you all for helping me to fix this issue.

Glad to help! Just from the path I can imagine you are building something amazing!

1 Like