将 cx_freeze 与 feedparser 导入一起使用时出错:ModuleNotFoundError: No module named 'sgmllib'

问题描述

我正在尝试使用 cx_freeze 来冻结使用 Feedparser 的应用程序。如果我使用 python 从命令行启动它,该应用程序将完美运行。但是,当我尝试使用 cx_freeze 冻结它时,在我尝试启动应用程序之前我不会收到错误消息。然后我得到:

Traceback (most recent call last):
  File "/home/ricky/.local/lib/python3.9/site-packages/cx_Freeze/initscripts/__startup__.py",line 66,in run
    module.run()
  File "/home/ricky/.local/lib/python3.9/site-packages/cx_Freeze/initscripts/Console.py",line 36,in run
    exec(code,m.__dict__)
  File "main.py",line 8,in <module>
  File "/home/ricky/.local/lib/python3.9/site-packages/Feedparser/__init__.py",line 28,in <module>
    from .api import parse
  File "/home/ricky/.local/lib/python3.9/site-packages/Feedparser/api.py",in <module>
    from .html import _BaseHTMLProcessor
  File "/home/ricky/.local/lib/python3.9/site-packages/Feedparser/html.py",line 31,in <module>
    from .sgml import *
  File "/home/ricky/.local/lib/python3.9/site-packages/Feedparser/sgml.py",line 30,in <module>
    import sgmllib
ModuleNotFoundError: No module named 'sgmllib'

我知道 sgmllib 在 Python 3 中不再使用,但是由于我从命令行启动它时没有收到此错误,因此它似乎不是 Feedparser 问题。有什么想法吗?

解决方法

cx_Freeze 开发人员在 Github 上帮助我解决了同样的问题。 Here's the thread.