如何在 python 中解决报错 ImportError: The 'pyparsing' package is required
问题描述
今天在敲代码的时候遇到了一个问题,报错信息如下所示:
File "D:\Python_Study\Github_Repositories\Hotspot-Detector\algorithm\net\ssd.py", line 7, in <module>
import torch
File "D:\Python\lib\site-packages\torch\__init__.py", line 29, in <module>
from .torch_version import __version__ as __version__
File "D:\Python\lib\site-packages\torch\torch_version.py", line 3, in <module>
from pkg_resources import packaging # type: ignore[attr-defined]
File "D:\Python\lib\site-packages\pkg_resources\__init__.py", line 83, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "D:\Python\lib\site-packages\pkg_resources\_vendor\packaging\requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "D:\Python\lib\site-packages\pkg_resources\extern\__init__.py", line 50, in load_module
raise ImportError(
ImportError: The 'pyparsing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution
这就很让人纳闷,上一秒同一个文件还跑的好好的,下一秒怎么就跑不起来了?更奇怪的是,连 VS Code 的格式化文件功能都不起作用了。
问题解决
又仔细看了一下自己的文件夹,发现刚才偷懒新建了一个 copy.py
文件,而恰好 python 自带了一个 copy
包,这样就命名冲突了。只要把 copy.py
改成其他名字就大功告成了~~