使用 PyInstaller 打包 Python 程序后执行,出现 'ModuleNotFoundError: No module named 'webencodings'' 错误,即使已经安装了 html5lib 和 webencodings,并在 spec 文件中将 html5lib 和 webencodings 都加入 hiddenimports 了。

Traceback (most recent call last):
  File "GetZhaiQuanFunddf.py", line 12, in <module>
  File "D:\Anaconda3\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "common.py", line 14, in <module>
  File "D:\Anaconda3\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\html5lib\__init__.py", line 25, in <module>
  File "D:\Anaconda3\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\html5lib\html5parser.py", line 6, in <module>
  File "D:\Anaconda3\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\html5lib\_inputstream.py", line 10, in <module>
ModuleNotFoundError: No module named 'webencodings'

可能是因为 PyInstaller 打包时没有正确处理依赖关系,可以尝试在 spec 文件中添加 webencodings 的路径,例如:

hiddenimports=['webencodings'],
datas=[('path/to/webencodings', 'webencodings')]

其中 datas 参数用于将 webencodings 的路径添加到打包后的文件中。如果仍然无法解决问题,可以尝试使用其他打包工具或手动安装 webencodings。

PyInstaller 打包后执行报错:'ModuleNotFoundError: No module named 'webencodings'' 解决方法

原文地址: https://www.cveoy.top/t/topic/f9xp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录