Navigation Menu

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

Importing markdown module under Python 3.8.5 yields "AttributeError: 'NoneType' object has no attribute 'loader'" #5269

Closed
4 of 6 tasks
chipmuenk opened this issue Oct 20, 2020 · 2 comments

Comments

@chipmuenk
Copy link

Description of the issue

I've used pyInstaller successfully to package my software https://github.com/chipmuenk/pyfda in the past (thanx!)

The problems described in the following only occur when using Python 3.8.5 in conjunction with the markdown module. I can package the software with Python 3.7 so this issue is no direct problem for me, I just wanted to report it.


My new release makes use of the markdown module. When run directly, it works without problem. When bundled, the application terminates immediately when it tries to import the markdown module for the first time with the message

File "markdown\htmlparser.py", line 30, in <module>
File "<frozen importlib._bootstrap>", line 553, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'

Full stack trace see below,

The markdown hook 'hook-markdown.py' is loaded automatically, the only warning that is directly related to the markdown module is

missing module named htmlentitydefs - imported by markdown.inlinepatterns (optional)

I get the same warning when running Python 3.7.4 (where the bundled executable works), in addition, here I get

missing module named importlib.metadata - imported by importlib (conditional), pluggy.manager (conditional), _pytest.compat (conditional), markdown.util (optional)

When I remove the markdown import (and all instantiations), the bundled application runs without problems under Python 3.8.5 as well. I use pyinstaller with pyinstaller pyfdax.spec, the spec-file can be seen at https://github.com/chipmuenk/pyfda/blob/develop/pyfdax.spec

The versions of some other packages modules are:

numpy 1.19.1
scipy 1.5.2
numexpr 2.7.1
matplotlib 3.2.2
Qt5 5.9.7
PyQt 5.9.2
Markdown 3.3.1
docutils 0.16
migen
mplcursors 0.3

Context information (for bug reports)

  • Output of pyinstaller --version: 4.0 or 4.1dev0
  • Version of Python: 3.8.5 (Anaconda distribution)
  • Platform: Windows 10 (64 bit)
  • Did you also try this on another platform? Does it work there?

Yes, running the same script with Python 3.7.4 under Windows 10 or Ubuntu 20.04 works flawlessly.

  • try the latest development version, using the following command:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

yes, made no difference

Make sure everything is packaged correctly

  • start with clean installation
  • use the latest development version
  • Run your frozen program from a command window (shell) — instead of double-clicking on it
  • Package your program in --onedir mode
  • Package without UPX, say: use the option --noupx or set upx=False in your .spec-file
  • Repackage you application in verbose/debug mode. For this, pass the option --debug to pyi-makespec or pyinstaller or use EXE(..., debug=1, ...) in your .spec file.

A minimal example program which shows the error

(paste text here)
“Minimal“ means: remove everything from your code which is not relevant for this bug,
esp. don't use external programs, remote requests, etc.
A very good example is https://gist.github.com/ronen/024cdae9ff2d50488438. This one helped
us reproducing and fixing a quite complex problem within approx 1 hour.

Stacktrace / full error message

The actual error occurs in line 22 in "pyfda\libs\pyfda_lib.py" which just contains import markdown

Traceback (most recent call last):
  File "pyfda\pyfdax.py", line 32, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\chris\anaconda3\envs\mpl_33_fresh\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "pyfda\libs\pyfda_lib.py", line 22, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\chris\anaconda3\envs\mpl_33_fresh\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "markdown\__init__.py", line 29, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\chris\anaconda3\envs\mpl_33_fresh\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "markdown\core.py", line 27, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\chris\anaconda3\envs\mpl_33_fresh\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "markdown\preprocessors.py", line 29, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\chris\anaconda3\envs\mpl_33_fresh\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
    exec(bytecode, module.__dict__)
  File "markdown\htmlparser.py", line 30, in <module>
  File "<frozen importlib._bootstrap>", line 553, in module_from_spec
AttributeError: 'NoneType' object has no attribute 'loader'
[9316] Failed to execute script pyfdax

Please also see https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs
for more about what would use to solve the issue.

@rokm
Copy link
Member

rokm commented Oct 20, 2020

This looks like the issue that should be fixed by pyinstaller/pyinstaller-hooks-contrib#56. Until new version of pyinstaller-hooks-contrib is tagged, you will need to update pyinstaller-hooks-contrib manually:
pip install https://github.com/pyinstaller/pyinstaller-hooks-contrib/archive/master.zip

(Or, you can try adding html.parser to hidden imports).

@chipmuenk
Copy link
Author

You're right, this has nothing to do with the python version, I have markdown 3.2 installed on the environments where the bundle runs correctly. Adding

hiddenimports += ['html.parser'] # needed for markdown 3.3 compatibility

worked for me. Thanks a lot!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants