操作系统:Window 10 x64
我尝试在 Python 解析器中导入 serial 模块,但是出现以下错误:
>>> import serial
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'serial'
退出 Python 解析器,在 Powershell 中使用 pip list
命令列出已经安装的包,发现并没有 pySerial:
PS C:\Users\Admin> pip list
Package Version
----------- -------
argcomplete 1.12.3
click 8.0.2
colorama 0.4.4
packaging 21.0
pip 21.2.4
pipx 0.16.4
pyparsing 2.4.7
setuptools 58.2.0
userpath 1.7.0
wheel 0.37.0
查看 pySerial 文档,根据 Installation 章节的提示,安装 pySerial(第 1 行):
PS C:\Users\Admin> pip install pyserial
Collecting pyserial
Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Installing collected packages: pyserial
Successfully installed pyserial-3.5
重新执行 pip list
命令,可见已经安装 pySerial(第 11 行):
PS C:\Users\Admin> pip list
Package Version
----------- -------
argcomplete 1.12.3
click 8.0.2
colorama 0.4.4
packaging 21.0
pip 21.2.4
pipx 0.16.4
pyparsing 2.4.7
pyserial 3.5
setuptools 58.2.0
userpath 1.7.0
wheel 0.37.0
重启 Powershell,在 Python 解析器中导入 serial 模块,就不会报错了。
如果要卸载 pySerial,可以使用 pip uninstall pyserial
命令:
PS C:\Users\Admin> pip uninstall pyserial
Found existing installation: pyserial 3.5
Uninstalling pyserial-3.5:
Would remove:
c:\users\admin\appdata\local\programs\python\python310\lib\site-packages\pyserial-3.5.dist-info\*
c:\users\admin\appdata\local\programs\python\python310\lib\site-packages\serial\*
c:\users\admin\appdata\local\programs\python\python310\scripts\pyserial-miniterm.exe
c:\users\admin\appdata\local\programs\python\python310\scripts\pyserial-ports.exe
Proceed (Y/n)? y
Successfully uninstalled pyserial-3.5