Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'sgmllib' #901

Closed
pepoboyii opened this issue Jan 28, 2021 · 12 comments
Closed

ModuleNotFoundError: No module named 'sgmllib' #901

pepoboyii opened this issue Jan 28, 2021 · 12 comments

Comments

@pepoboyii
Copy link

So I made an RSS reader with feedparser and used cx_Freeze to make it an .exe. But then the .exe wouldn't run so I ran it through Command Prompt and got the error in the title.

@marcelotduarte
Copy link
Owner

How you freeze the app, using command line cxfreeze or using setup.py?
You can use the includes or the packages option
https://cx-freeze.readthedocs.io/en/latest/script.html#cmdoption-includes
https://cx-freeze.readthedocs.io/en/latest/distutils.html

@pepoboyii
Copy link
Author

Including the module with either includes= or with packages= gives then the error during the freezing:
ImportError: No module named 'sgmllib'
I'm using Python 3.9 and I'm aware sgmllib was dropped but since it runs fine on the command line it's not a feedparser issue.

@marcelotduarte
Copy link
Owner

What version of cx_Freeze you are using? It is marked as excluded in python3 since 6.1 or 6.2.
Then, try to use excludes.

@pepoboyii
Copy link
Author

pepoboyii commented Jan 29, 2021

cx_Freeze (6.5.3)
Using excludes= gives the same error of ModuleNotFoundError

@marcelotduarte
Copy link
Owner

can you put the traceback (maybe the last 10 lines)

@pepoboyii
Copy link
Author

pepoboyii commented Jan 29, 2021

Using includes traceback when freezing:

  File "C:\Users\user\AppData\Local\Programs\Python\Python39\Scripts\cxfreeze.exe\__main__.py", line 7, in <module>
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\cx_Freeze\main.py", line 255, in main
    freezer.Freeze()
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\cx_Freeze\freezer.py", line 758, in Freeze
    self.finder = self._GetModuleFinder()
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\cx_Freeze\freezer.py", line 463, in _GetModuleFinder
    finder.IncludeModule(name)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\cx_Freeze\finder.py", line 638, in IncludeModule
    module = self._import_module(name, deferred_imports)
  File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\cx_Freeze\finder.py", line 291, in _import_module
    raise ImportError(f"No module named {name!r}")
ImportError: No module named 'sgmllib'

Using excludes or nothing traceback when trying to run the .exe:

File "test.py", line 1, in <module>
 File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\feedparser\__init__.py", line 28, in <module>
   from .api import parse
 File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\feedparser\api.py", line 36, in <module>
   from .html import _BaseHTMLProcessor
 File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\feedparser\html.py", line 31, in <module>
   from .sgml import *
 File "c:\users\user\appdata\local\programs\python\python39\lib\site-packages\feedparser\sgml.py", line 30, in <module>
   import sgmllib
ModuleNotFoundError: No module named 'sgmllib'

@marcelotduarte
Copy link
Owner

marcelotduarte commented Jan 29, 2021

PR #904 fix this.
You can download the wheels in https://github.com/marcelotduarte/cx_Freeze/suites/1925511446/artifacts/37932928
Extract the wheel for your python in the zip and install with pip install name_of_whell
And change your setup to use includes, to include de module 'sgmllib'

@pepoboyii
Copy link
Author

This worked. Gracias!

@marcelotduarte
Copy link
Owner

cx_Freeze 6.6 has just been released.

@alexfromapex
Copy link

alexfromapex commented May 20, 2022

Has there been a regression on this? I am having this issue on an M1 Mac, I've tried adding sgml to the setup.py (using Python 3.8.10, Poetry, and PyEnv):

...
"packages": ["feedparser","feedparser.sgml","sgmllib"],
"includes": ["feedparser","feedparser.sgml","sgmllib"],
"excludes": [],
 ...

but still having the issue:

Traceback (most recent call last):
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/cx_Freeze/initscripts/__startup__.py", line 113, in run
    module_init.run(name + "__main__")
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/cx_Freeze/initscripts/Console.py", line 15, in run
    exec(code, module_main.__dict__)
  File "Feeder.py", line 3, in <module>
  File "/Users/alex/Code/Python/Feeder/ui/rss_panel.py", line 4, in <module>
    import feedparser
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/feedparser/__init__.py", line 28, in <module>
    from .api import parse
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/feedparser/api.py", line 37, in <module>
    from .html import _BaseHTMLProcessor
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/feedparser/html.py", line 31, in <module>
    from .sgml import *
  File "/Users/alex/Library/Caches/pypoetry/virtualenvs/feeder-NpbTmY5B-py3.8/lib/python3.8/site-packages/feedparser/sgml.py", line 30, in <module>
    import sgmllib
ModuleNotFoundError: No module named 'sgmllib'

In the missing modules list it still appears:

? sgmllib imported from feedparser.sgml

Not sure if it's being caused by a virtualenv from PyEnv or Poetry?

@marcelotduarte
Copy link
Owner

@alexfromapex This must be sufficient:

options={
        "build_exe": {"includes": ["sgmllib"]},
    },

@alexfromapex
Copy link

alexfromapex commented May 20, 2022

Works perfectly, thank you! 🚀 I was confused and thought that build_exe was a build format similar to bdist_mac and bdist_dmg but I understand now that its options will apply to any format you build, so for any future readers this works now with python setup.py bdist_mac:

options = {
    "includes": ["sgmllib"],
    "excludes": []
}
base = None

setup(
    name="...",
    version="0.1",
    description="...",
    options={ "build_exe": options },
    executables=[Executable("<your .py file>", base=base)],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants