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)
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.
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)
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.
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.
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