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

'Extra' extension issue with pyinstaller #884

Closed
madgrizzle opened this issue Nov 26, 2019 · 3 comments
Closed

'Extra' extension issue with pyinstaller #884

madgrizzle opened this issue Nov 26, 2019 · 3 comments

Comments

@madgrizzle
Copy link

@madgrizzle madgrizzle commented Nov 26, 2019

I posted this on stackoverflow because I thought it was a pyinstaller issue, but I'm wondering if it's really a python-markdown issue.

https://stackoverflow.com/questions/59052079/pyinstaller-and-python-markdown-importerror-no-module-named-extra

I'm running into an issue trying to get python-markdown to work in pyinstaller. I have this code to demonstrate the issue in file called test.py:

import markdown

testMarkdown = "blahdy blah blah"
print(markdown.markdown(testMarkdown))
print(markdown.markdown(testMarkdown, extensions=["extra"]))

When I run it using python3, I get as desired:

(venv) C:\Users\madgrizzle>python3 test.py
<p>blahdy blah blah</p>
<p>blahdy blah blah</p>

I run pyinstaller as follows:

(venv) C:\Users\madgrizzle>pyinstaller test.py

and run the resulting code, I get the following:

(venv) C:\Users\madgrizzle\dist\test>test
<p>blahdy blah blah</p>
Traceback (most recent call last):
  File "test.py", line 5, in <module>
  File "lib\site-packages\markdown\core.py", line 390, in markdown
  File "lib\site-packages\markdown\core.py", line 100, in __init__
  File "lib\site-packages\markdown\core.py", line 126, in registerExtensions
  File "lib\site-packages\markdown\core.py", line 166, in build_extension
  File "importlib\__init__.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 985, in _gcd_import
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
ImportError: No module named 'extra'
[14432] Failed to execute script test

I tried to rebuild using:

(venv) C:\Users\madgrizzle>pyinstaller --hidden-import="markdown.extensions.extra" test.py

but I get the same error message.

Is there something special that's needed for including markdown extensions?

Additional Information:

It appears that the 'extra' extension might be causing the problem. Per https://python-markdown.github.io/extensions/extra/, 'extra' is a compilation of multiple extensions, including fenced_code and tables. If I just try to use the tables extension by itself, pyinstaller works IF I use the full-name as follows:

markdown.markdown(testMarkdown, extensions=["markdown.extensions.tables"])

If instead of using 'markdown.extensions.tables' I use 'markdown.extensions.extra', compile using pyinstaller, and run it, it responds back with a missing "fenced_code" module. Basically, it seems I have to avoid 'extra' with pyinstaller.

@waylan
Copy link
Member

@waylan waylan commented Nov 26, 2019

There are three ways to load an extension:

  1. Pass in an instance of the class.
  2. Pass in the full importable path (markdown.extensions.tables).
  3. Pass in a short name for the extension (tables).

The way the third option works is that extensions are registered on install with a setuptools entrypoint. When Markdown receives a string, it checks for an entrypoint with the same name and, if it finds one, it uses it (if it fails, it then falls back to trying to import the string as an importable path). My assumption is that pyinstaller is not playing nice with entrypoints. Therefore, if you are using pyinstaller, you cannot use the short names for extensions.

However, the extra extension uses the short names internally. I suppose this could be considered a bug as it limits the extension to only work where entrypoints are fully supported. The problem is that by using entrypoints, its easy to pass extension configs to each individual extension within extra. That's not so easy if we do something else. In other words, a solution is not immediately clear.

@waylan
Copy link
Member

@waylan waylan commented Nov 26, 2019

I just remembered that we broke support for markdown=1 out into its own extension (see #859). That being the case, as of the next release (3.2), extra will only be a shortcut to calling a bunch of other extensions and will offer no functionality of its own. Therefore, users can just call the extensions it bundles separately with no loss of functionality. Given the above, I don't think we will bother to address this.

If we do anything, we probably should just deprecate the extra extension.

@waylan waylan removed the bug label Nov 26, 2019
@madgrizzle
Copy link
Author

@madgrizzle madgrizzle commented Nov 26, 2019

Thanks, seems reasonable and just including the full list of extensions in markdown.markdown isn't much of a burden.

@waylan waylan added wontfix and removed needs-decision labels Jun 26, 2020
@waylan waylan closed this Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.